我有一个 jqgrid,它从 xml 流加载数据(由 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 经过测试以针对不同的时间戳返回不同的数据。
我已经使用alert(document.getElementById('datepicker_start').value)检查了触发重新加载事件时日期输入中的值是否正确传递。
您知道为什么数据不更新吗?也许是缓存或浏览器问题?
最佳答案
在我看来你应该更换
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");
) 将在 jQuery.ajax
调用时读取 datepicker 中的值。
关于jquery - jqgrid 重新加载时不更新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2826478/