Reputation: 3118
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:'/downtime/list_xml/',
datatype: 'xml',
mtype: 'GET',
postData:{site:1,date_start:document.getElementById('datepicker_start').value,date_end:document.getElementById('datepicker_end').value},
colNames:[...],
colModel :[...],
pager: '#pager',
rowNum: 25,
rowList:[10,25,50],
viewrecords: true,
height: 500,
caption: 'Click on column headers to reorder'
});
$("#grid_reload").click(function(){
$("#list").trigger("reloadGrid");
});
$("#tabs").tabs();
$("#datepicker_start").datepicker({dateFormat: 'yy-mm-dd'});
$("#datepicker_end").datepicker({dateFormat: 'yy-mm-dd'});
...
And the html elements:
<th>Start Date:</th>
<td><input id="datepicker_start" type="text" value="2009-12-01"></input></td>
<th>End Date:</th>
<td><input id="datepicker_end" type="text" value="2009-12-03"></input></td>
<td><input id="grid_reload" type="submit" value="load" /></td>
When I click the grid_reload button, the grid reloads, but when it has done so it shows exactly the same data as before, even though the xml is tested to return different data for different timestamps.
I have checked using alert(document.getElementById('datepicker_start').value) that the values in the date inputs are passed correctly when the reload event is triggered.
Any ideas why the data doesn't update? A caching or browser issue perhaps?
Upvotes: 1
Views: 15190
Reputation: 21
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}
});
Upvotes: 2
Reputation: 221997
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.
Upvotes: 3
Reputation: 134167
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:
GridUnload
to unload the grid,.jqGrid
again to reinitialize the entire gridurl
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.
Upvotes: 2