如何在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