作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用日期字段过滤 jQgrid 数据。请看我下面的图片。
我的网页中有两个文本框和一个按钮。我尝试过滤客户数据
在所选日期范围之间。我在按钮单击事件中调用了 setGridParam。
请在下面查看我的 HTML。
$("#Button1").click(function () {
var fromdate = $("#txtFrom").val();
var todate = $("#txtTo").val();
jQuery("#jQGridDemo").jqGrid('setGridParam', {
url: "/Home/GetFilterData?sidx=" + fromdate + "&sord=" + todate, page: 1
}).trigger("reloadGrid");
});
这是我的 Controller Action
[HttpPost]
public JsonResult GetFilterData(string sidx, string sord)
{
using (jQGridDemoEntities db = new jQGridDemoEntities())
{
var customers = new List<Customer>();
customers = db.Customers.ToList();
return Json((
from customer in customers
orderby customer.Id descending
select new[]{
customer.Id.ToString(CultureInfo.InvariantCulture),
customer.FirstName,
customer.LastName,
customer.IsMale.ToString(),
customer.Address,
customer.Email,
customer.Phone,
customer.Country.Name,
customer.Note,
customer.Created.ToString()
}).ToArray(), JsonRequestBehavior.AllowGet);
}
}
我在 SetGridParam 函数中调用了这个函数,但是这个 Action 没有被触发。
最佳答案
参数 sidx
和 sord
是根据选项 sortname
和 sortorder
动态构建的。因此,如果您确实需要设置参数,则应将 setGridParam
与具有 sortname
和 sortorder
属性的对象一起使用。
您使用 fromdate
和 todate
作为 sidx
和 sord
的值。所以我怀疑您只需要向服务器发送一些附加 参数,然后尝试使用现有参数。这不是最好的方法。我建议您引入附加参数fromDate
和toDate
并使用postData
参数作为jqGrid 选项的功能:
// create jqGrid with additional postData parameter
$("#jQGridDemo").jqGrid({
url: "/Home/GetFilterData",
postData: {
fromDate: function () {
return $("#txtFrom").val();
},
toDate: function () {
return $("#txtTo").val();
}
},
...
});
$("#Button1").click(function () {
$("#jQGridDemo").trigger("reloadGrid", [{page: 1}]);
});
您还需要将 GetFilterData
操作的参数名称更改为对应于 postData
的属性名称:
public JsonResult GetFilterData(string fromDate, string toDate)
{
...
}
我推荐你阅读the answer和 this one了解更多信息。
关于javascript - jQGrid setGridParam 函数不适用于 MVC 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22316388/
我是一名优秀的程序员,十分优秀!