Skip to content

Commit 6bf64ef

Browse files
Fixed duplicate AJAX requests on grid filter keypress (#502)
Co-authored-by: trabulium <mcampbell@mageaustralia.com.au>
1 parent 2f8db6c commit 6bf64ef

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

public/js/mage/adminhtml/grid.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,15 @@ class varienGrid {
252252
bindFilterFields() {
253253
// Use event delegation on document body to catch all filter keypresses
254254
// This survives AJAX reloads since body doesn't get replaced
255-
if (!document.body._gridFilterDelegated) {
255+
// Track per-grid to support multiple grids on the same page
256+
document.body._gridFilterDelegated = document.body._gridFilterDelegated || {};
257+
if (!document.body._gridFilterDelegated[this.containerId]) {
256258
document.body.addEventListener('keypress', (event) => {
257-
// Check if this is a filter field in our grid
258259
if (event.target.matches(`#${this.containerId} .filter input, #${this.containerId} .filter select`)) {
259260
this.filterKeyPress(event);
260261
}
261262
});
262-
document.body._gridFilterDelegated = true;
263-
}
264-
265-
// Also try direct binding as fallback
266-
const filters = document.querySelectorAll('#' + this.containerId + ' .filter input, #' + this.containerId + ' .filter select');
267-
for (let i = 0; i < filters.length; i++) {
268-
filters[i].addEventListener('keypress', this.filterKeyPress.bind(this));
263+
document.body._gridFilterDelegated[this.containerId] = true;
269264
}
270265
}
271266

0 commit comments

Comments
 (0)