KendoGrid - 应用自定义过滤器然后导航到下一页或任何其他页面后,过滤器值未传递给控制器
KendoGrid - After applying custom filter and then navigating to next or any other page, the filter values are not getting passed to controller
二手Kendo版本:2015.2.624
我已经使用附加参数实现了 kendogrid 服务器端分页。下面是我的控制器的样子:
public ActionResult GetData([DataSourceRequest] DataSourceRequest request, DateTime startDate, DateTime endDate, int state = -1, string poolName = null, string submitter = null)
{
poolName = string.IsNullOrEmpty(poolName) ? null : poolName;
submitter = string.IsNullOrEmpty(submitter) ? null : submitter;
var summarylist = new List<Summary>();
var total = 0;
using (var db = new SummaryEntities())
{
var jobs = db.SummaryTable.Where(k => k.created >= startDate && k.created <= endDate)
.Where(k => state != -1 ? k.state == state : k.state > state)
.Where(k => poolName != null ? k.pool_name == poolName : k.pool_name != null)
.Where(k => submitter != null ? k.submitter == submitter : k.submitter != null);
jobs = jobs.OrderByDescending(job => job.id);
total = jobs.Count();
// Apply paging...
if (request.Page > 0)
{
jobs = jobs.Skip((request.Page - 1) * request.PageSize);
}
jobs = jobs.Take(request.PageSize);
foreach (var job in jobs)
{
summarylist.Add(new Summary(job));
}
}
var result = new DataSourceResult()
{
Data = summarylist,
Total = total
};
return Json(result, JsonRequestBehavior.AllowGet);
}
其他参数是用户在小部件日期选择器、输入框等上设置的当前值
下面是我的数据源在网格中的样子:
<script type="text/javascript">
j$ = jQuery.noConflict();
j$(document).ready(function () {
j$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "/Home/GetData/",
dataType: "json",
data: {
startDate: j$("#startdate").val(),
endDate: j$("#enddate").val()
}
}
},
pageSize: 30,
serverPaging: true,
schema: {
data: 'Data',
total: 'Total'
}
},
height: j$(window).height() - 85,
groupable: true,
sortable: true,
filterable: false,
columnMenu: true,
pageable: true,
columns: [
{ field: "JobId", title: "Job Id", template: '<a href="/home/jobs/#:JobId#" target="_blank">#:JobId#</a>', type: "number" },
{ field: "Name", title: "Job Name", hidden: true },
{ field: "PoolName", title: "Pool Name" },
{ title: "Date Time", columns: [{ field: "Start", title: "Start" },
{ field: "End", title: "End" }
],
headerAttributes: {
"class": "table-header-cell",
style: "text-align: center"
}
},
{ field: "State", title: "State" },
{
title: "Result", columns: [{ field: "ResultPassed", title: "P" },
{ field: "ResultFailed", title: "F" }
],
headerAttributes: {
"class": "table-header-cell",
style: "text-align: center"
}
},
{ field: "Submitter", title: "Submitter" }
]
});
});
</script>
在我观察到这个问题之前,它工作得很好:
- 更改过滤器值,即提交者、日期范围等,以及
控制器在附加参数中获取所有这些信息,其中
我正在采取相应的措施,效果很好。
- 现在假设从步骤 1 返回的结果有多个页面并且
当您单击下一页、最后一页或任何其他页码时,
控制器被调用,这是预期的,但额外的
在步骤 1 中设置的参数不会再次传递
默认值在那里破坏了一切。
更正:
其他参数仅在客户端丢失。
现在请告诉我我在这里遗漏了什么?
预期结果:在步骤 2 中,不应丢失其他参数,并且应与步骤 1 相同。
感谢任何帮助。
已编辑:
完整的控制器和电网代码。
谢谢,
维尼特
我从 telerik 支持团队那里得到了解决方案:
回复:
所描述的不良行为可能是由以下附加参数引起的:
data: {
startDate: j$("#startdate").val(),
endDate: j$("#enddate").val()
}
... 被设置为对象,而不是函数。如果将它们设置为函数,则每次调用 read() 时都会计算相应输入的值,并传递当前值(如 API 参考中的第二个示例所示):
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read.data
二手Kendo版本:2015.2.624
我已经使用附加参数实现了 kendogrid 服务器端分页。下面是我的控制器的样子:
public ActionResult GetData([DataSourceRequest] DataSourceRequest request, DateTime startDate, DateTime endDate, int state = -1, string poolName = null, string submitter = null)
{
poolName = string.IsNullOrEmpty(poolName) ? null : poolName;
submitter = string.IsNullOrEmpty(submitter) ? null : submitter;
var summarylist = new List<Summary>();
var total = 0;
using (var db = new SummaryEntities())
{
var jobs = db.SummaryTable.Where(k => k.created >= startDate && k.created <= endDate)
.Where(k => state != -1 ? k.state == state : k.state > state)
.Where(k => poolName != null ? k.pool_name == poolName : k.pool_name != null)
.Where(k => submitter != null ? k.submitter == submitter : k.submitter != null);
jobs = jobs.OrderByDescending(job => job.id);
total = jobs.Count();
// Apply paging...
if (request.Page > 0)
{
jobs = jobs.Skip((request.Page - 1) * request.PageSize);
}
jobs = jobs.Take(request.PageSize);
foreach (var job in jobs)
{
summarylist.Add(new Summary(job));
}
}
var result = new DataSourceResult()
{
Data = summarylist,
Total = total
};
return Json(result, JsonRequestBehavior.AllowGet);
}
其他参数是用户在小部件日期选择器、输入框等上设置的当前值
下面是我的数据源在网格中的样子:
<script type="text/javascript">
j$ = jQuery.noConflict();
j$(document).ready(function () {
j$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "/Home/GetData/",
dataType: "json",
data: {
startDate: j$("#startdate").val(),
endDate: j$("#enddate").val()
}
}
},
pageSize: 30,
serverPaging: true,
schema: {
data: 'Data',
total: 'Total'
}
},
height: j$(window).height() - 85,
groupable: true,
sortable: true,
filterable: false,
columnMenu: true,
pageable: true,
columns: [
{ field: "JobId", title: "Job Id", template: '<a href="/home/jobs/#:JobId#" target="_blank">#:JobId#</a>', type: "number" },
{ field: "Name", title: "Job Name", hidden: true },
{ field: "PoolName", title: "Pool Name" },
{ title: "Date Time", columns: [{ field: "Start", title: "Start" },
{ field: "End", title: "End" }
],
headerAttributes: {
"class": "table-header-cell",
style: "text-align: center"
}
},
{ field: "State", title: "State" },
{
title: "Result", columns: [{ field: "ResultPassed", title: "P" },
{ field: "ResultFailed", title: "F" }
],
headerAttributes: {
"class": "table-header-cell",
style: "text-align: center"
}
},
{ field: "Submitter", title: "Submitter" }
]
});
});
</script>
在我观察到这个问题之前,它工作得很好:
- 更改过滤器值,即提交者、日期范围等,以及 控制器在附加参数中获取所有这些信息,其中 我正在采取相应的措施,效果很好。
- 现在假设从步骤 1 返回的结果有多个页面并且 当您单击下一页、最后一页或任何其他页码时, 控制器被调用,这是预期的,但额外的 在步骤 1 中设置的参数不会再次传递 默认值在那里破坏了一切。
更正:
其他参数仅在客户端丢失。
现在请告诉我我在这里遗漏了什么?
预期结果:在步骤 2 中,不应丢失其他参数,并且应与步骤 1 相同。
感谢任何帮助。
已编辑: 完整的控制器和电网代码。
谢谢, 维尼特
我从 telerik 支持团队那里得到了解决方案:
回复:
所描述的不良行为可能是由以下附加参数引起的:
data: {
startDate: j$("#startdate").val(),
endDate: j$("#enddate").val()
}
... 被设置为对象,而不是函数。如果将它们设置为函数,则每次调用 read() 时都会计算相应输入的值,并传递当前值(如 API 参考中的第二个示例所示):
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read.data