bootstrap-table 中實現,點擊翻頁,記錄上頁/下頁選中的行


 

bootstrap-table中實現,翻頁之后再返回,依然選中的情況

 

 1 //var productids = $("body",window.parent.frames[0].document).find('.ptids');//textarea存放數據
 2 var productids = $('textarea');
 3 var merge_order_object= {};//頁碼+id組成的對象
 4 var jsonObj = {};
 5 var current_page = "";//當前頁碼
 6 
 7 //表格渲染完成操作
 8 table.on('post-body.bs.table', function (e, settings, json, xhr) {
 9 
10   var merge_order_arr = [];
11   var objString = productids.val();
12   if(objString !== ""){
13     jsonObj = JSON.parse(objString);//轉換為json對象
14     $.map(jsonObj, function (arr) {
15       // merge_order_arr.push.apply(merge_order_arr,arr);//合並數組
16       merge_order_arr = merge_order_arr.concat(arr);//合並數組
17     });
18     $.each(settings,function (i,v) {
19       $.each(merge_order_arr,function (index,value) {
20         if(v.id === parseInt(value)){
21           $(e.target).find('tbody tr').eq(i).find('input').click();
22         }
23       });
24     });
25     // productids.val( objString );
26   }
27   // debugger;
28 });
29 $('input[name="btSelectAll"], table tbody, input[name="btSelectItem"]').change(function () {//復選框
30   current_page = table.bootstrapTable('getOptions').pageNumber;
31   merge_order_object[current_page] = Table.api.selectedids(table);
32   productids.val( JSON.stringify(merge_order_object) );//轉換成字符串
33 
34 });

 

 1 // 獲取選中的條目ID集合
 2 selectedids: function (table) {
 3     var options = table.bootstrapTable('getOptions');
 4     if (options.templateView) {
 5         return $.map($("input[data-id][name='checkbox']:checked"), function (dom) {
 6             return $(dom).data("id");
 7         });
 8     } else {
 9         return $.map(table.bootstrapTable('getSelections'), function (row) {
10             return row[options.pk];
11         });
12     }
13 },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM