Coffeescript DataTables-选择插件-带分页的多行选择无法记住选择

Coffeescript DataTables-选择插件-带分页的多行选择无法记住选择,coffeescript,datatables,Coffeescript,Datatables,我需要确保我可以使用DataTables,1.10来使用Select插件-设置分页,但是当使用服务器端处理时,所选项目消失了,我可以看到几十个引用和黑客,但感觉某个地方的人已经干净地解决了这个问题 我希望能够跨分页记住选定的行 咖啡脚本如下: $('#users-table').dataTable processing: true serverSide: true select: true rowId: 'row_id' def

我需要确保我可以使用DataTables,1.10来使用Select插件-设置分页,但是当使用服务器端处理时,所选项目消失了,我可以看到几十个引用和黑客,但感觉某个地方的人已经干净地解决了这个问题

我希望能够跨分页记住选定的行

咖啡脚本如下:

    $('#users-table').dataTable
      processing: true
      serverSide: true
      select: true
      rowId: 'row_id'
      deferRender: true
      ajax: $('#users-table').data('source')
      pagingType: 'full_numbers'
      columns: [
        { data: 'name' }
        { data: 'phone' }
        { data: 'address' }
      ]

有明显的解决方案吗?

当您定义了
rowId
时,您可以将所选行的
id
存储在数组
select
中。每次绘制时,在页面的可见行之间循环,并重新选择先前选择的任何行:

select = []

# row is selected, add to array
table.on 'select', (e, dt, type, indexes) ->
  rowId = table.row(indexes[0]).id()
  if ! ~select.indexOf(rowId)
    select.push rowId
  return

# row is deselected, remove from array
table.on 'deselect', (e, dt, type, indexes) ->
  rowId = table.row(indexes[0]).id()
  index = select.indexOf(rowId)
  if index > -1
    select.splice index, 1
  return

# on each draw, cycle trough visible rows
# re-select rows if their id appears in the select array 
table.on 'draw', ->
  table.rows().every (rowIdx, tableLoop, rowLoop) ->
    if ~select.indexOf(@id())
      @select()
    return
  return
希望它在咖啡脚本中也能起作用。已使用


多选:

table.on 'select', (e, dt, type, indexes) ->
  indexes.forEach (id) ->
    rowId = table.row(id).id()
    if ! ~select.indexOf(rowId)
      select.push rowId
    return
  return

table.on 'deselect', (e, dt, type, indexes) ->
  indexes.forEach (id) ->
    rowId = table.row(id).id()
    index = select.indexOf(rowId)
    if index > -1
      select.splice index, 1
    return
  return

工作,但需要多个选择,应该很容易mod@user1320651好的,它是为了支持multi-select(这就是我测试它的方式,也是我使用数组的原因)-但是你需要在选项中设置
select:'multi'
,还需要它与select-all一起工作,所以它就快到了;-),它只接受第一个select值,但应该使用rows_selected=table.rows().rows({selected:true})并循环使用它来添加值。您可以编辑帖子以包含全选选项吗?@user1320651,您可以在
选择
/
取消选择
上迭代
索引
?请参阅更新。如何选择全部?