The default layui table does not have the selected status of the source page after the page is jumped. If you want to record the selected state of the source page, you need to define a global variable to record the selected state of the data.
1. Modify
;(["laytpl", "laypage", "layer", "form"], function (e) { "use strict"; var t = layui.$, i = , a = , l = , n = , o = (), r = (), d = { //layuiPageCheckedIds variable records the selected data id, the format is ",1,2,3,4," string config: {checkName: "LAY_CHECKED", indexName: "LAY_TABLE_INDEX", layuiPageCheckedIds: ","}, cache: {}, index: ? + 1e4 : 0, set: function (e) { var i = this; return = ({}, , e), i }, on: function (e, t) { return (this, s, e, t) } } ... = function (e, i) { var a = this, n = , o = , r = , d = function () { "object" == typeof && (, ) }; if ( = (new Date).getTime(), ) { var c = {}; //Put the selected data into the condition before sending the request if( != undefined && "" != ){ = ; } if(tableRender){ var currPageNumber = getPageNumber(); c[] = currPageNumber; tableRender = false; }else{ setPageNumberCookie(e); c[] = e; } c[] = ; ({ type: || "get", url: , data: (c, ), dataType: "json", success: function (t) { if(null != startLoading){ (startLoading); startLoading = null; } return t[] != ? ((), ('<div class="' + f + '">' + (t[] || "Returned data status exception") + "</div>")) : ((t, e, t[]), d(), = (new Date).getTime() - + " ms", i && (i), void("function" == typeof && (t, e, t[]))) }, error: function (e, t) { ('<div class="' + f + '">Data interface request exception</div>'), (), i && (i) } }); } else if ( && === Array) { if(null != startLoading){ (startLoading); startLoading = null; } var s = {}, u = e * - ; s[] = ().splice(u, ), s[] = , (s, e, ), d(), "function" == typeof && (s, e, s[]) } } ... //Add to set the selected variable at the end of the file //Set the initial selected value ,=function(e,i){ if(i == undefined || i == ""){ i = ""; } if( > 0 && "," != (0,1)){ i = "," + i; } if( > 0 && "," != ( - 1, )){ i = i + ","; } [e].layuiPageCheckedIds = i; }, //Get the selected ids, parameter e represents the id of the table =function (e) { return [e].layuiPageCheckedIds; }, //Set the selected ids, e represents the id of the table, obj represents the selected row data, v represents which parameter to record =function (e,obj,v) { var a = [e]; var layuiPageCheckedIds = ; //Select all buttons if( == "all"){ //Select all if () { var checkStatus = (e); var datas = ; for(var i = 0; i < ; i++) { layuiPageCheckedIds = (layuiPageCheckedIds, datas[i][v]); } } //Cancel all selection else { var cache = ; var datas = cache[e]; for(var i = 0; i < ; i++) { layuiPageCheckedIds = (layuiPageCheckedIds, datas[i][v]); } } } //Select a single line else { //Select if () { layuiPageCheckedIds = (layuiPageCheckedIds, [v]); } //Unselect else { layuiPageCheckedIds = (layuiPageCheckedIds, [v]); } } = layuiPageCheckedIds; }, //Add a selection =function(layuiPageCheckedIds, seleted){ if(layuiPageCheckedIds == undefined || layuiPageCheckedIds == ""){ return "," + seleted + ","; }else{ return layuiPageCheckedIds + seleted + ","; } }, //Unselect item =function (layuiPageCheckedIds, seleted) { var match = "," + seleted + ","; var pos = (match); if (pos >= 0) { return (0, pos) + (pos + - 1); } } });
2. Set the data selection status according to the id in the background
@RequestMapping(value = "/search", method = ) @ResponseBody public Map<String, Object> search(Pageable pageable, @RequestParam List<Long> layuiCheckedIds) { Map<String, Object> rst = new HashMap<>(4); ("code", 0); ("msg", ""); Page<Person> page = (pageable); ("count", ()); List<Map<String, Object>> datas = new ArrayList<>(8); for (Person person : ()) { Map<String, Object> view = new HashMap<>(4); ("id", ()); ("name", ()); // If () has been selected, set the selected state if (!(layuiCheckedIds) && (())) { ("LAY_CHECKED", true); } ... (view); } ("data", datas); return rst; }
3. Front-end usage
("table", function(){ var table = ; //Set initial selection var checkedIds = "1,2,3,4"; ({ elem: '#test', url:"./person/search", where: {"layuiCheckedIds": checkedIds }, ,cols: [[ {type:'checkbox', width:'10%'}, {field:'id', title: 'ID', width:'20%'}, {field:'name', title: 'Name', width:'15%'} ]], page: true, id:'idTest' }); //Initialize the selected item ('idTest', checkedIds ); //Select the check box of the monitor table ('checkbox(demo)', function(obj){ //Set multiple page selection effect //The first parameter represents the id value of the table, the second parameter represents the data selected in the check box, and the third parameter represents which attribute value to be parsed (here is the parsing of the id attribute in the data model). ('idTest',obj, "id"); //Get all selected id values (for example: ",1,2,5,7,3,15,22") //alert(('idTest')); }); });
The above example of the above layui table check box jumped to the page and then returned to maintain the original selected state is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.