dataTables bStateSave本地存储页面上的多个表

时间:2015-01-19 16:11:20

标签: ruby-on-rails datatables

我有一个使用dataTables的Rails应用程序。为了在同一页面上有多个表,我有几个ID。这工作正常,但bStateSave不起作用。 bStateSave在只有一个dataTable的页面上工作正常。

这是我的代码:

  $("#dataTable0").dataTable
    bStateSave: true
    bStateDuration: 0
    fnStateSave: (oSettings, oData) ->
      localStorage.setItem "DataTables_" + window.location.pathname, JSON.stringify(oData)
    fnStateLoad: (oSettings) ->
      JSON.parse localStorage.getItem("DataTables_" + window.location.pathname)
    ....

  $("#dataTable1").dataTable(
    bStateSave: true
    bStateDuration: 0
    fnStateSave: (oSettings, oData) ->
      localStorage.setItem "DataTables_" + window.location.pathname, JSON.stringify(oData)
    fnStateLoad: (oSettings) ->
      JSON.parse localStorage.getItem("DataTables_" + window.location.pathname)
    ...

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我做了以下更改:

  $("#dataTable0").dataTable
    bStateSave: true
    bStateDuration: 0
    fnStateSave: (oSettings, oData) ->
      localStorage.setItem "DataTables_" + window.location.pathname + "-" + 0, JSON.stringify(oData)
    fnStateLoad: (oSettings) ->
      JSON.parse localStorage.getItem("DataTables_" + window.location.pathname + "-" + 0)

$("#dataTable1").dataTable
    bStateSave: true
    bStateDuration: 0
    fnStateSave: (oSettings, oData) ->
      localStorage.setItem "DataTables_" + window.location.pathname + "-" + 1, JSON.stringify(oData)
    fnStateLoad: (oSettings) ->
      JSON.parse localStorage.getItem("DataTables_" + window.location.pathname + "-" + 1)