Kendo ui KendoGrid-应用自定义筛选器,然后导航到下一页或任何其他页后,筛选器值不会传递给控制器
使用剑道版本:2015.2.624 我已经用附加参数实现了kendogrid服务器端分页。以下是我的控制器的外观:Kendo ui KendoGrid-应用自定义筛选器,然后导航到下一页或任何其他页后,筛选器值不会传递给控制器,kendo-ui,kendo-grid,kendo-asp.net-mvc,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,使用剑道版本:2015.2.624 我已经用附加参数实现了kendogrid服务器端分页。以下是我的控制器的外观: public ActionResult GetData([DataSourceRequest] DataSourceRequest request, DateTime startDate, DateTime endDate, int state = -1, string poolName = null, string submitter = null) { poolName
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);
}
public ActionResult GetData([DataSourceRequest]DataSourceRequest请求,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=新列表();
var合计=0;
使用(var db=new SummaryEntities())
{
var jobs=db.SummaryTable.Where(k=>k.created>=startDate&&k.created state!=-1?k.state==state:k.state>state)
.Where(k=>poolName!=null?k.pool\u name==poolName:k.pool\u name!=null)
.其中(k=>提交者!=null?k.提交者==提交者:k.提交者!=null);
jobs=jobs.OrderByDescending(job=>job.id);
总数=jobs.Count();
//应用分页。。。
如果(request.Page>0)
{
jobs=jobs.Skip((request.Page-1)*request.PageSize);
}
jobs=jobs.Take(request.PageSize);
foreach(作业中的var作业)
{
summarylist.Add(新摘要(作业));
}
}
var result=新数据源结果()
{
数据=汇总列表,
总计=总计
};
返回Json(结果,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>
j$=jQuery.noConflict();
j$(文档).ready(函数(){
j$(“#网格”).kendoGrid({
数据源:{
运输:{
阅读:{
url:“/Home/GetData/”,
数据类型:“json”,
数据:{
startDate:j$(“#startDate”).val(),
结束日期:j$(“#结束日期”).val()
}
}
},
页面大小:30,
对,,
模式:{
数据:'数据',
总计:“总计”
}
},
高度:j$(窗口)。高度()-85,
分组:对,
可排序:是的,
可过滤:false,
专栏菜单:是的,
pageable:对,
栏目:[
{字段:“作业Id”,标题:“作业Id”,模板:“”,类型:“编号”},
{字段:“名称”,标题:“职务名称”,隐藏:true},
{字段:“池名”,标题:“池名”},
{标题:“日期时间”,列:[{字段:“开始”,标题:“开始”},
{字段:“结束”,标题:“结束”}
],
校长致辞:{
“类”:“表头单元格”,
样式:“文本对齐:居中”
}
},
{字段:“州”,标题:“州”},
{
标题:“结果”,列:[{field:“ResultPassed”,标题:“P”},
{字段:“ResultFailed”,标题:“F”}
],
校长致辞:{
“类”:“表头单元格”,
样式:“文本对齐:居中”
}
},
{字段:“提交人”,标题:“提交人”}
]
});
});
在我观察到这个问题之前,它工作得相当好:
Vineet我从telerik支持团队获得了解决方案: 回复: 所述不期望的行为可能由以下事实引起:
data: {
startDate: j$("#startdate").val(),
endDate: j$("#enddate").val()
}
。。。设置为对象,而不是函数。如果将它们设置为函数,则每次调用read()时都会计算相应输入的值,并传递当前值(如API参考中的第二个示例所示):
我从telerik支持团队那里得到了解决方案: 回复: 所述不期望的行为可能由以下事实引起:
data: {
startDate: j$("#startdate").val(),
endDate: j$("#enddate").val()
}
。。。设置为对象,而不是函数。如果将它们设置为函数,则每次调用read()时都会计算相应输入的值,并传递当前值(如API参考中的第二个示例所示):
您可以发布更多的
GetData
控制器功能吗。您是否使用Kendo.DynamicLinq代码>控制器中的库?添加了控制器和网格的完整代码。您可以发布更多的GetData
controller函数吗。您是否使用Kendo.DynamicLinq代码>控制器中的库?添加了控制器和网格的完整代码。