2016-12-26 69 views
1

當我從我的數據表的第2頁點擊特定條目時,它將我重定向到另一頁,當我回來時它將我重定向到第1頁。 這裏的問題是我想保存狀態我想回到從我被重定向到的頁面(例如:2)。角數據表saveState不起作用

.withOption('bStateSave',true) 
    .withOption('stateSaveCallback', function (aoData, oSettings) { 
     console.log('performing save of settings'); 
     localStorage.setItem('DataTables_home', JSON.stringify(aoData)) ; 
    }) 
    .withOption('stateLoadCallback', function (oSettings) { 
     console.log('performing load of settings'); 
     return JSON.parse(localStorage.getItem('DataTables_home')); 
    }); 

錯誤:

Unexpected token o in JSON at position 1 
    at Object.parse (<anonymous>) 
    at jQuery.fn.init.<anonymous> (app.js:14430) 
    at _fnLoadState (jquery.dataTables.js:6308) 
    at HTMLTableElement.<anonymous> (jquery.dataTables.js:1221) 
    at Function.each (base.js:365) 
    at jQuery.fn.init.each (base.js:137) 
    at jQuery.fn.init.DataTable [as dataTable] (jquery.dataTables.js:869) 
    at jQuery.fn.init.$.fn.DataTable (jquery.dataTables.js:15105) 
    at Object.renderDataTable (angular-datatables.js:757) 
    at Object.hideLoadingAndRenderDataTable (angular-datatables.js:773) 

Cannot read property 'parentNode' of null 
    at _Api.<anonymous> (jquery.dataTables.js:9213) 
    at _Api.iterator (jquery.dataTables.js:6978) 
    at _Api.<anonymous> (jquery.dataTables.js:9212) 
    at _Api.destroy (jquery.dataTables.js:7141) 
    at jQuery.fn.init.DataTable.fnDestroy (jquery.dataTables.js:412) 
    at HTMLTableElement.<anonymous> (jquery.dataTables.js:923) 
    at Function.each (base.js:365) 
    at jQuery.fn.init.each (base.js:137) 
    at jQuery.fn.init.DataTable [as dataTable] (jquery.dataTables.js:869) 
    at jQuery.fn.init.$.fn.DataTable (jquery.dataTables.js:15105) 

這將真正幫助很多,如果你能爲我提供了一個例子。 謝謝。 V1 jQuery的版本:2.2.4 數據表版本:1.10.12 角的DataTable版本:0.5.5

回答

0

我使用 角版本版本該問題使用以下代碼解決:

<table id="example" datatable 
    dt-options="showCase.dtOptions" 
    dt-columns="showCase.dtColumns"> 
</table> 

vm.dtOptions = DTOptionsBuilder.fromSource('data.json') 
    .withOption('stateSave', true) 
    .withOption('stateSaveCallback', function(settings,data) { 
    localStorage.setItem('DataTables_' + settings.sInstance, JSON.stringify(data)); 
    }) 
    .withOption('stateLoadCallback', function(settings) { 
    return JSON.parse(localStorage.getItem('DataTables_' + settings.sInstance)) 
    });