如何在jQuery Datatables分页中返回特定页面?

[英]How to return the specific page in jQuery Datatables paging?


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' %}"
  });

4 个解决方案

#1


27  

DataTables has option to store state in a cookie.

DataTables可以选择在cookie中存储状态。

$(document).ready(function() {
    $('#example').dataTable( {
        "stateSave": true
    } );
} );

http://datatables.net/examples/basic_init/state_save.html

#2


5  

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

#3


4  

How to return the specific page in jQuery Datatables paging?

如何在jQuery Datatables分页中返回特定页面?

Use 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.

获取有关DataTable当前用于显示每个页面的分页设置的信息,包括显示的记录数,数据集中的起点和终点等。

      $.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 );
      }
      } );
      } );

Source: http://datatables.net/plug-ins/api

#4


1  

Here is how to do it in v1.10.7:

以下是在v1.10.7中的操作方法:

$(document).ready(function() {
    $('#example').dataTable( {
        stateSave: true
     } );
} );

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/07/09/692719e1f13c728e344ebf95ce8251fc.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com