如何在 jQuery Datatables 分页中返回特定页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11400459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to return the specific page in jQuery Datatables paging?
提问by Burak
I have a datable and "Edit" button in each row. When I click that button, /edit/ url opens. Everything is Ok until now. But if I need to go back to the datatable, it starts from the first page. What can I do for that?
我在每一行都有一个数据和“编辑”按钮。当我单击该按钮时, /edit/ url 打开。到目前为止一切都很好。但是如果我需要回到数据表,它会从第一页开始。我能为此做什么?
$('#table').dataTable({
"sDom" : 'rtFip>',
'fnDrawCallback' : function() {
$('input:checkbox, input:radio').checkbox();
},
'sPaginationType' : 'full_numbers',
"bServerSide" : true,
"sAjaxSource" : "{% url 'get_menu_list' %}"
});
回答by dotjoe
DataTables has option to store state in a cookie.
DataTables 可以选择在 cookie 中存储状态。
$(document).ready(function() {
$('#example').dataTable( {
"stateSave": true
} );
} );
回答by tponthieux
Storing the state in a cookie fails for large tables. This local storage solution works for large tables.
对于大表,将状态存储在 cookie 中失败。这种本地存储解决方案适用于大表。
$(document).ready(function() {
$('#example').dataTable( {
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
localStorage.setItem( 'DataTables', JSON.stringify(oData) );
},
"fnStateLoad": function (oSettings) {
return JSON.parse( localStorage.getItem('DataTables') );
}
} );
} );
Source: http://datatables.net/blog/localStorage_for_state_saving
来源:http: //datatables.net/blog/localStorage_for_state_saving
回答by Control Freak
How to return the specific page in jQuery Datatables paging?
如何在 jQuery Datatables 分页中返回特定页面?
Use fnPagingInfo
用 fnPagingInfo
Get information about the paging settings that DataTables is currently using to display each page, including the number of records shown, start and end points in the data set etc.
获取有关 DataTables 当前用于显示每个页面的分页设置的信息,包括显示的记录数、数据集中的起点和终点等。
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
};
$(document).ready(function() {
$('#example').dataTable( {
"fnDrawCallback": function () {
alert( 'Now on page'+ this.fnPagingInfo().iPage );
}
} );
} );
回答by Chuck
Here is how to do itin v1.10.7:
这里是如何做到这一点的v1.10.7:
$(document).ready(function() {
$('#example').dataTable( {
stateSave: true
} );
} );