Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9292585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:54:55+00:00 2026-06-18T20:54:55+00:00

I think this user was asking the same question I’m asking, but the reason

  • 0

I think this user was asking the same question I’m asking, but the reason driving his question was different, so he accepted a different solution. I need to do what he was originally asking:

Automatically cancelling jqgrid request

My jqGrid has a search toolbar (the input fields that appear below the column headers but above the data). Most of the columns have dropdowns (stype=select) that list the available filter options for that column, with an ‘All’ option at the top. The server-side code that responds with the JSON data that populates my jqGrid is complex and therefore somewhat slow, especially when there isn’t much in the way of filter criteria. This means that if the user selects ‘All’, it may be several seconds before any results show up. This is fine by itself, but if the user makes another filter selection before the response comes back, the grid does not cancel the existing request, nor does it submit a new one, so at some point after the user makes the second selection, the grid updates to show the response for the first selection. Furthermore, the grid auto-updates when you change the filter selection, so to get it to show the data you wanted, you have to change your selection to something else, wait for that to load, and then change it back.

Here’s what I’ve tried so far:

$(document).ready(setupGrid);

var currentGridRequest;

function setupGrid() {
    var grid = $("#grid").jqGrid({
        ...
        loadError: function(xhr, status, error) {
            currentGridRequest = undefined;
        },
        loadComplete: function(data) {
            currentGridRequest = undefined;
        },
        loadBeforeSend: function(xhr, settings) {
            if (currentGridRequest !== undefined) {
                currentGridRequest.abort();
            }
            currentGridRequest = xhr;
        }
    });
}

The problem I have is that the loadBeforeSend event doesn’t actually fire if there’s already a request in flight. I’ve tried a other events from the event documentation page (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events): beforeRequest and jqGridToolbarBeforeSearch both exhibit the same behavior.

What can I do to abort the in-flight request and proceed with searching based on the user’s most recent selection? Is this a bug in jqGrid? I initially encountered this issue on version 4.2; I’ve just upgraded to 4.4.4 with no change in this behavior.

Looking at the jqGrid code, the behavior I’m seeing appears to be unavoidable without changing the jqGrid code itself. jqGrid sets a flag (ts.grid.hDiv.loading) at the beginning of each request and clears it at the end; when this flag is set, new filter criteria will not be submitted and no events will fire.

I also considered modifying my JSON response so that it included the request criteria, and then write some JS code to compare the response to the current criteria selection. If they didn’t match, I’d ignore the response and not render it to the grid. Since jqGrid doesn’t even SUBMIT the second set of criteria, that option is off the table (and even if I can fix that problem, my current approach seems preferable).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:54:57+00:00Added an answer on June 18, 2026 at 8:54 pm

    I’ve found a way to do what I wanted. I use jqGrid in several places (including multiple grids on the same page in a few cases), so I factored it out into a function I can call from anywhere and which contains its own scope for managing whether there is a current request; just pass it a grid and it will attach all of the necessary event handlers. Note that this will overwrite any existing handlers you may have defined for the relevant events.

    function applyJqgridHandlers(grid) {
        (function(self, undefined) {
            var currentRequest;
            function abortCurrentRequestIfAny() {
                if (currentRequest !== undefined) {
                    currentRequest.abort();
                }
            }
            self.clearCurrentRequest = function() {
                abortCurrentRequestIfAny();
                currentRequest = undefined;
            };
            self.setCurrentRequest = function(xhr) {
                abortCurrentRequestIfAny();
                currentRequest = xhr;
            };
        })(grid.currentRequestHolder = {});
    
        grid.currentRequestHolder.clearCurrentRequest();
        grid.jqGrid('setGridParam', {
            loadError: function(xhr, status, error) {
                grid.currentRequestHolder.clearCurrentRequest();
            },
            loadBeforeSend: function(xhr, settings) {
                grid.currentRequestHolder.setCurrentRequest(xhr);
            },
            loadComplete: function(data) {
                grid.currentRequestHolder.clearCurrentRequest();
            }
        });
        grid.bind('jqGridToolbarBeforeSearch', function() {
            grid.currentRequestHolder.clearCurrentRequest();
            this.grid.hDiv.loading = false;
        });
    };
    

    Then I simply add a call to this function from the end of setupGrid().

    This code explicitly clears the ts.grid.hDiv.loading flag, which is not part of the published jqGrid API, so I consider this solution to be fairly fragile; there’s no guarantee that it would continue to work for future versions of jqGrid. If anyone has any suggestions for better (less fragile) ways to solve this problem, I’m all ears. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this could be a very easy question for you. But I have
(I think this is a pretty basic question on OOP, but unfortunately I wasn't
Sorry for asking an complete n00b question, but I've tried everything I can think
How can I force validation when user clicks button? One would think this should
I think this is a simple and a silly question. I have included a
I think this is a pretty straightforward problem but... var outerHeight = $('.profile').outerHeight(); $(#total-height).text(outerHeight
There's a same question I keep asking myself each time a new Dependency Injection
This question seems like a duplicate but it's really not. Just a slight difference
I am preparing a application in which i am asking user to upload his
I do a lot of php and javascript, but I think this is relatively

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.