CRM-18286 - Use localStorage to remember datatable page length
authorColeman Watts <coleman@civicrm.org>
Wed, 4 May 2016 20:59:22 +0000 (16:59 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 4 May 2016 21:06:28 +0000 (17:06 -0400)
js/Common.js

index c936f4f386c36b87590f357975bc89487468ddcb..60c156b9da68b0694415f5e6d8dfd1a6ca980368 100644 (file)
@@ -729,7 +729,11 @@ if (!CRM.vars) CRM.vars = {};
 
   $.fn.crmAjaxTable = function() {
     return $(this).each(function() {
-      //Declare the defaults for DataTables
+      // Recall pageLength for this table
+      if ($(this).data('ajax') && window.localStorage && localStorage['dataTablePageLength:' + $(this).data('ajax')]) {
+        $(this).data('pageLength', localStorage['dataTablePageLength:' + $(this).data('ajax')]);
+      }
+      // Declare the defaults for DataTables
       var defaults = {
         "processing": true,
         "serverSide": true,
@@ -755,6 +759,12 @@ if (!CRM.vars) CRM.vars = {};
       };
       //Include any table specific data
       var settings = $.extend(true, defaults, $(this).data('table'));
+      // Remember pageLength
+      $(this).on('length.dt', function(e, settings, len) {
+        if (settings.ajax && window.localStorage) {
+          localStorage['dataTablePageLength:' + settings.ajax] = len;
+        }
+      });
       //Make the DataTables call
       $(this).DataTable(settings);
     });