Skip to content

Commit e92ee8a

Browse files
authored
Improve persistent parameter checking
1 parent 1574504 commit e92ee8a

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

assets/datagrid.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,28 +349,32 @@ document.addEventListener('change', function(e) {
349349

350350

351351
window.datagridSerializeUrl = function(obj, prefix) {
352-
var str = [];
353-
for(var p in obj) {
354-
if (obj.hasOwnProperty(p)) {
355-
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
356-
if (v !== null && v !== "") {
357-
if (window.location.pathname.includes('/' + v)) {
358-
continue;
359-
}
360-
if (typeof v == "object") {
361-
var r = window.datagridSerializeUrl(v, k);
352+
const str = [];
353+
let urlPathForPersistentChecking = window.location.pathname;
354+
355+
for (const p in obj) {
356+
if (obj.hasOwnProperty(p)) {
357+
const k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
358+
if (v !== null && v !== "") {
359+
// fix for persistent nette parameters
360+
if (urlPathForPersistentChecking.includes('/' + v)) {
361+
urlPathForPersistentChecking = urlPathForPersistentChecking.replace('/' + v, '');
362+
continue;
363+
}
364+
if (typeof v == "object") {
365+
const r = window.datagridSerializeUrl(v, k);
362366
if (r) {
363367
str.push(r);
364368
}
365-
} else {
366-
str.push(encodeURIComponent(k) + "=" + encodeURIComponent(v));
369+
} else {
370+
str.push(encodeURIComponent(k) + "=" + encodeURIComponent(v));
371+
}
367372
}
368373
}
369374
}
370-
}
371-
return str.join("&");
372-
}
373-
;
375+
376+
return str.join("&");
377+
};
374378

375379
datagridSortable = function() {
376380
if (typeof $.fn.sortable === 'undefined') {

0 commit comments

Comments
 (0)