jqgrid not updating data on reload

前端 未结 3 1579
春和景丽
春和景丽 2020-12-22 04:38

I have a jqgrid with data loading from an xml stream (handled by django 1.1.1):

jQuery(document).ready(function(){
  jQuery(\"#list\").jqGrid({
    url:\'/do         


        
相关标签:
3条回答
  • 2020-12-22 04:38

    It seems to me you should replace

    postData:{
        site:1,
        date_start:document.getElementById('datepicker_start').value,
        date_end:document.getElementById('datepicker_end').value
    },
    

    with

    postData:{
        site:1,
        date_start: function() { return document.getElementById('datepicker_start').value; },
        date_end: function() { return document.getElementById('datepicker_end').value;}
    },
    

    UPDATED: In your current solution the value of postData are calculated one time as you create jqGrid. In the postData with functions jqGrid forward postData to jQuery.ajax and during every jQuery.ajax (after $("#list").trigger("reloadGrid");) the values from datepicker will be read at the moment of jQuery.ajax call.

    0 讨论(0)
  • 2020-12-22 05:01

    Unloading the grid before making a new request seem to bust the cache for me. Simple use GridUnload() method before the grid fetching code.

    $("#list").GridUnload();
    
    
    jQuery("#list").jqGrid({
        ...
        ajaxGridOptions: {cache: false}
    });
    
    0 讨论(0)
  • 2020-12-22 05:03

    It looks like a browser caching issue. By default, IE will cache the results of a GET request. So even if you make the same request multiple times from the same browser instance, if it is for the same URL it will always use the cached version (IE, data from the first request).

    Internally, jqGrid uses jQuery.ajax to retrieve data. You can instruct jqGrid to pass additional options to the ajax request via the option ajaxGridOptions. So just tell it to not cache results and you should be good to go:

    jQuery("#list").jqGrid({
        ...
        ajaxGridOptions: {cache: false}
    });
    

    Alternatively:

    If the first approach does not work with django due to the construction of the GET URL (since jQuery will use the ? construction), another possible option is to completely reload the grid. To do so:

    • Call GridUnload to unload the grid,
    • Then call .jqGrid again to reinitialize the entire grid
    • You would also need to append a timestamp to the url option to guarantee the URL is unique, otherwise it will just be cached again.

    Obviously this is not as nice of a solution, but it would work.

    0 讨论(0)
提交回复
热议问题