From d5cd8c4aa85748bbadba80cb889005adca238386 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/js/Common.js b/js/Common.js index c936f4f386c3..c50b673c7848 100644 --- a/js/Common.js +++ b/js/Common.js @@ -729,13 +729,18 @@ if (!CRM.vars) CRM.vars = {}; $.fn.crmAjaxTable = function() { return $(this).each(function() { - //Declare the defaults for DataTables + // Recall pageLength for this table + var pageLength = 25; + if ($(this).data('ajax') && localStorage && localStorage['dataTablePageLength:' + $(this).data('ajax')]) { + pageLength = localStorage['dataTablePageLength:' + $(this).data('ajax')]; + } + // Declare the defaults for DataTables var defaults = { "processing": true, "serverSide": true, "aaSorting": [], "dom": '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>', - "pageLength": 25, + "pageLength": pageLength, "drawCallback": function(settings) { //Add data attributes to cells $('thead th', settings.nTable).each( function( index ) { @@ -755,6 +760,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 && localStorage) { + localStorage['dataTablePageLength:' + settings.ajax] = len; + } + }); //Make the DataTables call $(this).DataTable(settings); });