实现bootstrap-table中,翻页之后再返回,依然选中
javascript
//var productids = $("body",window.parent.frames[0].document).find('.ptids');//textarea存放数据
var productids = $('textarea');
var merge_order_object= {};//页码+id组成的对象
var jsonObj = {};
var current_page = "";//当前页码
//表格渲染完成操作
table.on('post-body.bs.table', function (e, settings, json, xhr) {
var merge_order_arr = [];
var objString = productids.val();
if(objString !== ""){
jsonObj = JSON.parse(objString);//转换为json对象
$.map(jsonObj, function (arr) {
// merge_order_arr.push.apply(merge_order_arr,arr);//合并数组
merge_order_arr = merge_order_arr.concat(arr);//合并数组
});
$.each(settings,function (i,v) {
$.each(merge_order_arr,function (index,value) {
if(v.id === parseInt(value)){
$(e.target).find('tbody tr').eq(i).find('input').click();
}
});
});
// productids.val( objString );
}
// debugger;
});
$('input[name="btSelectAll"], table tbody, input[name="btSelectItem"]').change(function () {//复选框
current_page = table.bootstrapTable('getOptions').pageNumber;
merge_order_object[current_page] = Table.api.selectedids(table);
productids.val( JSON.stringify(merge_order_object) );//转换成字符串
});
12345678910111213141516171819202122232425262728293031323334
javascript
// 获取选中的条目ID集合
selectedids: function (table) {
var options = table.bootstrapTable('getOptions');
if (options.templateView) {
return $.map($("input[data-id][name='checkbox']:checked"), function (dom) {
return $(dom).data("id");
});
} else {
return $.map(table.bootstrapTable('getSelections'), function (row) {
return row[options.pk];
});
}
},
12345678910111213
评论 (0)