Skip to content

Commit

Permalink
CRM-18286 - Strip the ids out of ajax urls to make them more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed May 6, 2016
1 parent 70c01f7 commit cf9fd95
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions js/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,16 @@ if (!CRM.vars) CRM.vars = {};
};

$.fn.crmAjaxTable = function() {
// Strip the ids from ajax urls to make pageLength storage more generic
function simplifyUrl(url) {
return typeof url === 'string' ? url.replace(/[&?]\w*id=\d+/g, '') : null;
}

return $(this).each(function() {
// Recall pageLength for this table
if ($(this).data('ajax') && window.localStorage && localStorage['dataTablePageLength:' + $(this).data('ajax')]) {
$(this).data('pageLength', localStorage['dataTablePageLength:' + $(this).data('ajax')]);
var url = simplifyUrl($(this).data('ajax'));
if (url && window.localStorage && localStorage['dataTablePageLength:' + url]) {
$(this).data('pageLength', localStorage['dataTablePageLength:' + url]);
}
// Declare the defaults for DataTables
var defaults = {
Expand Down Expand Up @@ -762,7 +768,7 @@ if (!CRM.vars) CRM.vars = {};
// Remember pageLength
$(this).on('length.dt', function(e, settings, len) {
if (settings.ajax && window.localStorage) {
localStorage['dataTablePageLength:' + settings.ajax] = len;
localStorage['dataTablePageLength:' + simplifyUrl(settings.ajax)] = len;
}
});
//Make the DataTables call
Expand Down

0 comments on commit cf9fd95

Please sign in to comment.