jiuhefree

问题

bootstrap table的复选框选中后,翻页操作会导致上一页选中的丢失

解决

将选中的值先存在一个全局的变量中,然后使用 formatter,示例如下:

table.bootstrapTable({
    url: $.fn.bootstrapTable.defaults.extend.index_url,
    sortName: \'id\',
    showToggle: false,
    showExport: false,
    columns: [
        [{
            field: \'state\',
            checkbox: true,
            formatter: function (i, row) {            // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
                if ($.inArray(row.id, idArr) != -1) {// 因为 判断数组里有没有这个 id
                    return {
                        checked: true               // 存在则选中
                    }
                }
            }
        }]
    ]
});

 

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2021-10-05
  • 2021-09-14
  • 2021-05-17
  • 2021-04-07
  • 2021-12-21
  • 2022-01-31
猜你喜欢
  • 2021-12-06
  • 2021-12-22
  • 2021-08-30
  • 2021-07-07
  • 2022-01-06
  • 2022-02-14
  • 2021-06-05
相关资源
相似解决方案