Home >Web Front-end >Layui Tutorial >How to refresh the current page for batch deletion in layui
1. First perform the visual interface operation, as shown in the figure, there are 2 pieces of data.
#2. Select the data to be deleted in batches.
3. Click the delete button and a prompt code will pop up
layer.confirm("确认删除勾选的专题?", {icon: 3, title:"确认"}, function(){ batchDel(resSubInfoIds); }, function(){ });
batchDel calls the real batch deletion method
4. The result interface after batch deletion.
Related recommendations: "layui Framework Tutorial"
5. The method of adding data will be used when deleting batches later. This, so this method is reused and will be used during the initial data loading and batch deletion processes:
function load(pageNum, params){ params = params || {}; params.current = pageNum; $.post(ctxBack+"/XXXXXX/list", params, function(result){ if(false === result.success){ layer.alert(result.message || "专题数据加载失败", {icon: 2,title:'错误'}); return; } laytpl(gridTpl).render(result.data.records, function(html){ $(gridPanelId + " table tbody").empty().append(html); }); //缓存查询参数 gridParams.page = result.data.current; gridParams.params = params; renderPage($(gridPanelId + " .panel-footer"), result.data, load, params); }).error(function(){ layer.alert("专题数据加载失败", {icon: 2,title:'错误'}); }); }
6. The deletion method, refreshing after batch deletion, is actually Request the initialization method again to load the data once. Use the ajax method to achieve no page refresh. The code is as follows:
/** * 删除专题 */ function del(){ var resSubInfoIds=getCheckedData(); if(resSubInfoIds == ""){ layer.msg("请选择需要删除的专题"); return ; } layer.confirm("确认删除勾选的专题?", {icon: 3, title:"确认"}, function(){ batchDel(resSubInfoIds); }, function(){ }); } /** * 批量删除 */ function batchDel(resSubInfoIds){ var loading = layer.load(2, { shade: [0.3,'#fff']}); params={resSubInfoIds:resSubInfoIds}; $.post(ctxBack+"/XXXXXX/batchDel", params, function(result){ if(false === result.success){ layer.alert(result.message || "专题删除失败", {icon: 2,title:'错误'}); return; } layer.msg("专题删除成功"); }).error(function(){ layer.alert("专题删除失败", {icon: 2,title:'错误'}); }).complete(function(){ layer.close(loading); //加载完成关闭loading load(gridParams.page, gridParams.params); //更新当前页 }); }
The above is the detailed content of How to refresh the current page for batch deletion in layui. For more information, please follow other related articles on the PHP Chinese website!