dataTables paging page number cache, search cache problem

Since the stateSave parameter is set to true, dataTables gets the paging information from the web store each time, causing the table to display the wrong page number (the last requested page number).
Workaround: stateSave : false.
Code Analysis:
[javascript]  view plain copy  
 
  1. if ( oInit.bStateSave )  
  2. {  
  3. features.bStateSave = true;  
  4. _fnLoadState( oSettings, oInit );  
  5. _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSaveState, 'state_save' );  
  6. }  

-------------------------------------------------- -------------------------------------------------- ----------------------------
_fnLoadState() function analysis:
[javascript]  view plain copy  
 
  1. //Get the last page number information (state) from the cache,  
  2. var state = settings.fnStateLoadCallback.call( settings.oInstance, settings );  
  3. if ( ! state || ! state.time ) {  
  4. return;  
  5. }  
  6.   
  7. //state and ajaxData are encapsulated into new setttings. The setting contains: all parameter data of dataTables, ajaxData data, current paging information, etc.  
  8. // Restore key features - todo - for 1.11 this needs to be done by  
  9. // subscribed events  
  10. settings._iDisplayStart    = state.start;  
  11. settings.iInitDisplayStart = state.start;  
  12. settings._iDisplayLength   = state.length;  
  13. settings.aaSorting = [];  
  14.   
  15. _fnCallbackFire( settings, 'aoStateLoaded''stateLoaded', [settings, state] );  
 

-------------------------------------------------- ------------------------------------------------
_fnSaveState( stttings) function analysis
[javascript]  view plain copy  
 
  1. // bStateSave=true, take out the cached state. Otherwise, return directly  
  2. if ( !settings.oFeatures.bStateSave || settings.bDestroying )  
  3. {  
  4. return;  
  5. }  
  6.   
  7. /* Store the interesting variables */  
  8. var  state = {  
  9. time:    +new Date(),  
  10. start:   settings._iDisplayStart,  
  11. length:  settings._iDisplayLength,  
  12. order:   $.extend( true, [], settings.aaSorting ),  
  13. search:  _fnSearchToCamel( settings.oPreviousSearch ),  
  14. columns: $.map( settings.aoColumns, function ( col, i ) {  
  15. return {  
  16. visible: col.bVisible,  
  17. search: _fnSearchToCamel( settings.aoPreSearchCols[i] )  
  18. };  
  19. } )  
  20. };  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326959565&siteId=291194637