当前位置: 代码迷 >> 综合 >> bootstrap table获取到翻页选中的值
  详细解决方案

bootstrap table获取到翻页选中的值

热度:67   发布时间:2024-02-12 02:01:46.0

1、在渲染表格处加上responseHandler属性

$table=$('#forkliftList').bootstrapTable({
method: "post",
url: 'forklift/queryForkliftListByTopOfficeIdAndOfficeId.do',
cache: false,
pagination: true,
dataField: 'rows',//rows
    singleSelect: false,
clickToSelect: true,
responseHandler:responseHandler,
queryParams: function (data) {
        data['plateNumber'] = $("#_plateNumber").val();
        data['topOfficeId'] = "${topOfficeId}";
        data['officeId'] = "${officeId}";
return data;
    },
columns: [
        {checkbox: true,formatter : stateFormatter},
        {field: 'plateNumber', title: $.i18n.prop('PlateNumber'), width: 80, align: 'center'},
        {field: 'brand', title: $.i18n.prop('Brand'), width: 80, align: 'center'},
        {field: 'model', title: $.i18n.prop('Model'), width: 80, align: 'center'},
        {field: 'topOfficeName', title: $.i18n.prop('Company'), width: 80, align: 'center'},
        {field: 'officeName', title: $.i18n.prop('Department'), width: 80, align: 'center'},
        {field: 'boxId', title: $.i18n.prop('DeviceNo'), width: 80, align: 'center'}
    ],
onLoadSuccess:function(data){
$("#forkliftList").bootstrapTable("checkBy", {field:"checked", values:[true]});
    }
});

2、添加responseHandler方法

//表格分页之前处理多选框数据
function responseHandler(res) {
$.each(res.rows, function (i, row) {
        row.checkStatus = $.inArray(row.id, selectionIds) != -1;   //判断当前行的数据id是否存在与选中的数组,存在则将多选框状态变为true
    });
return res;
}

3、get到翻页的值

var selectionIds = [];  //保存选中ids

for (var i = 0; i < selectionIds.length; i++) {
forkliftIdList.push(selectionIds[i]);
data['forkliftIdList'] = forkliftIdList.join(',');
}

  相关解决方案