gpt4 book ai didi

javascript - jQGrid setGridParam 函数不适用于 MVC 操作

转载 作者:行者123 更新时间:2023-11-29 10:44:27 25 4
gpt4 key购买 nike

我尝试使用日期字段过滤 jQgrid 数据。请看我下面的图片。

enter image description here

我的网页中有两个文本框和一个按钮。我尝试过滤客户数据

在所选日期范围之间。我在按钮单击事件中调用了 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 没有被触发。

最佳答案

参数 sidxsord 是根据选项 sortnamesortorder 动态构建的。因此,如果您确实需要设置参数,则应将 setGridParam 与具有 sortnamesortorder 属性的对象一起使用。

您使用 fromdatetodate 作为 sidxsord 的值。所以我怀疑您只需要向服务器发送一些附加 参数,然后尝试使用现有参数。这不是最好的方法。我建议您引入附加参数fromDatetoDate 并使用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 answerthis one了解更多信息。

关于javascript - jQGrid setGridParam 函数不适用于 MVC 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22316388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com