Skip to content

Commit

Permalink
CRM-18286 - Use localStorage to remember datatable page length
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed May 4, 2016
1 parent 08d3766 commit d5cd8c4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions js/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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);
});
Expand Down

0 comments on commit d5cd8c4

Please sign in to comment.