jqgrid在重新加载时不更新数据 [英] jqgrid not updating data on reload
问题描述
我有一个从 xml 流加载数据的 jqgrid(由 django 1.1.1 处理):
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'});
...
还有html元素:
<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>
当我单击 grid_reload 按钮时,网格会重新加载,但当它这样做时,它会显示与以前完全相同的数据,即使测试 xml 以针对不同的时间戳返回不同的数据.
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.
我已经使用 alert(document.getElementById('datepicker_start').value) 检查了在触发重新加载事件时日期输入中的值是否正确传递.
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?
推荐答案
在我看来你应该替换
postData:{
site:1,
date_start:document.getElementById('datepicker_start').value,
date_end:document.getElementById('datepicker_end').value
},
与
postData:{
site:1,
date_start: function() { return document.getElementById('datepicker_start').value; },
date_end: function() { return document.getElementById('datepicker_end').value;}
},
更新:在您当前的解决方案中,postData
的值在您创建 jqGrid 时计算一次.在带有函数 jqGrid 的 postData
中,将 postData
转发到 jQuery.ajax
并在每个 jQuery.ajax
期间(在 $("#list").trigger("reloadGrid");
) datepicker 中的值将在 jQuery.ajax
调用时被读取.
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.
这篇关于jqgrid在重新加载时不更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!