From 70c01f7d6b5e8ace1a4867e255d74e84e27cd85a Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 4 May 2016 16:59:22 -0400 Subject: [PATCH] CRM-18286 - Use localStorage to remember datatable page length --- js/Common.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/Common.js b/js/Common.js index c936f4f386..60c156b9da 100644 --- a/js/Common.js +++ b/js/Common.js @@ -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); }); -- 2.25.1