jqgrid不会在重新加载时更新数据 [英] jqgrid not updating data on reload

查看:157
本文介绍了jqgrid不会在重新加载时更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jqgrid,可以从xml流中加载数据(由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;}
},

已更新: 在当前解决方案中,创建jqGrid时会一次计算postData的值.在具有功能jqGrid的postData中,将postData转发到jQuery.ajax,并且在每个jQuery.ajax(在$("#list").trigger("reloadGrid");之后)期间,将在jQuery.ajax调用时读取datepicker的值.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆