DataTables(Table jQuery 的插件)在离开和返回 DataTable 时从您离开的地方继续
DataTables (Table plug-in for jQuery) continue where you left off when navigating away from and back to a DataTable
我一直在使用 DataTables 使站点管理员可以轻松搜索数据库数据。我收到了很多请求,要求用户在单击条目并导航回 table 时能够从他们在 DataTable 中离开的地方继续。我知道我可以从头开始,并可能通过主要是服务器端解决方案将此功能引入 table,但我希望有一种稍微简单的方法来捕获客户端的 DataTables 数据,并且将它提供给我的服务器端应用程序,以便能够在他们导航回它时重新绘制数据table 他们离开的地方。我想坚持使用 DataTables 的主要原因是我正在将它动态地用于将近 50 个不同的数据库 table,我真的不想为所有这些 table 实施一个完全不同的解决方案秒。我更愿意以这样一种方式使用 DataTables,即我可以将此功能动态添加到所有 50 页的 Datatables 中。任何有用的指示将不胜感激。
可能需要注意的是,我在服务器端使用PHP。 (更具体地说是 Symfony2 框架)。
您可能不得不进入浏览器历史记录操作并查看 HTML5 history.pushStat。网上有很多很好的教程。看看:
http://diveintohtml5.info/history.html
有关历史操纵的更多信息。
DataTables 有一些内置功能来处理这个问题。文档将其称为 "state saving".
来自文档:
DataTables has the option of being able to save the state of a table (its paging position, ordering state etc) so that is can be restored when the user reloads a page, or comes back to the page after visiting a sub-page.
这是使用传递给 DataTables 方法的配置对象中的 stateSave
选项启用的,如下所示:
$(document).ready(function() {
$('#example').dataTable( {
stateSave: true
} );
} );
您还可以使用 stateDuration
选项控制保存的时间长度。
请注意文档中的警告:
The built in state saving method uses the HTML5 localStorage and sessionStorage APIs for efficient storage of the data. Please note that this means that the built in state saving option will not work with IE6/7 as these browsers do not support these APIs.
DataTables 提供了 stateSaveCallback
和 stateLoadCallback
选项来解决这个问题,如果您需要支持那些较旧的浏览器(例如,通过使用 cookie 或服务器端解决方案)。
完整的文档可以在这里找到:https://datatables.net/examples/basic_init/state_save.html
我一直在使用 DataTables 使站点管理员可以轻松搜索数据库数据。我收到了很多请求,要求用户在单击条目并导航回 table 时能够从他们在 DataTable 中离开的地方继续。我知道我可以从头开始,并可能通过主要是服务器端解决方案将此功能引入 table,但我希望有一种稍微简单的方法来捕获客户端的 DataTables 数据,并且将它提供给我的服务器端应用程序,以便能够在他们导航回它时重新绘制数据table 他们离开的地方。我想坚持使用 DataTables 的主要原因是我正在将它动态地用于将近 50 个不同的数据库 table,我真的不想为所有这些 table 实施一个完全不同的解决方案秒。我更愿意以这样一种方式使用 DataTables,即我可以将此功能动态添加到所有 50 页的 Datatables 中。任何有用的指示将不胜感激。
可能需要注意的是,我在服务器端使用PHP。 (更具体地说是 Symfony2 框架)。
您可能不得不进入浏览器历史记录操作并查看 HTML5 history.pushStat。网上有很多很好的教程。看看:
http://diveintohtml5.info/history.html
有关历史操纵的更多信息。
DataTables 有一些内置功能来处理这个问题。文档将其称为 "state saving".
来自文档:
DataTables has the option of being able to save the state of a table (its paging position, ordering state etc) so that is can be restored when the user reloads a page, or comes back to the page after visiting a sub-page.
这是使用传递给 DataTables 方法的配置对象中的 stateSave
选项启用的,如下所示:
$(document).ready(function() {
$('#example').dataTable( {
stateSave: true
} );
} );
您还可以使用 stateDuration
选项控制保存的时间长度。
请注意文档中的警告:
The built in state saving method uses the HTML5 localStorage and sessionStorage APIs for efficient storage of the data. Please note that this means that the built in state saving option will not work with IE6/7 as these browsers do not support these APIs.
DataTables 提供了 stateSaveCallback
和 stateLoadCallback
选项来解决这个问题,如果您需要支持那些较旧的浏览器(例如,通过使用 cookie 或服务器端解决方案)。
完整的文档可以在这里找到:https://datatables.net/examples/basic_init/state_save.html