Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatically canceling jqGrid request
    primarykey
    data
    text
    <p>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:</p> <p><a href="https://stackoverflow.com/questions/13571433/automatically-cancelling-jqgrid-request">Automatically cancelling jqgrid request</a></p> <p>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 <em>after</em> the user makes the second selection, the grid updates to show the response for the <em>first</em> selection. Furthermore, the grid auto-updates when you <em>change</em> 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.</p> <p>Here's what I've tried so far:</p> <pre><code>$(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; } }); } </code></pre> <p>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 (<a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events" rel="nofollow noreferrer">http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events</a>): beforeRequest and jqGridToolbarBeforeSearch both exhibit the same behavior. </p> <p>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.</p> <p>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.</p> <p>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).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload