[请帮助我-为什么我在C#控制器中没有得到过滤器请求参数?我无法尝试在控制器端获取所有过滤器数据:
How to perform server side filtering on Kendo UI Grid
https://www.telerik.com/forums/how-to-do-server-side-filtering
HTML代码
<div id="grid" class="kendo-grid mobilegrid"></div>
使用jQuery的UI代码
$("#grid").kendoGrid({
ServerOperation: true,
dataSource: {
transport: {
read: {
url: '/Partners/GetAllPartnersContactDetails1', //using jsfiddle echo service to simulate JSON endpoint
type: "POST",
dataType: "json",
async: true,
//cache: false,
contentType: 'application/json',
data: function (e) {
debugger;
var grid = $("#grid").data("kendoGrid");
var $filter = new Array();
grid.dataSource.filter(e.filter);
console.log(e);
return e;
}
},
parameterMap: function (data, type) {
return kendo.stringify(data);
}
},
schema: {
data: function (result) {
return result.Data;
},
total: function (result) {
return result.Total;
}
},
type: "json",
serverPaging: true,
serverFiltering: true,
pageSize: 25,
},
filterable: {
mode: 'row',
operators: {
string: {
contains: "contains"
}
}
},
pageable: {
pageSizes: pageSizesArray,
numeric: false,
messages: {
itemsPerPage: "@Resources.Shared.ItemsPerPage",
display: "@Resources.Shared.PagingItemMsg",
empty: "@Resources.Shared.NoData"
}
//refresh: true,
},
height: $(window).height() *85/100,
filterable: {
mode: "row",
operators: {
string: {
contains: 'containsStringFilter',
eq: 'eqStringFilter',
neq: 'neqStringFilter',
isnull: 'isnullStringFilter',
isnotnull: 'isnotnullStringFilter',
isempty: 'isemptyStringFilter',
isnotempty: 'isnotemptyStringFilter',
startswith: 'startswithStringFilter',
doesnotcontain: 'doesnotcontainStringFilter',
endswith: 'endswithStringFilter',
isnullorempty: 'isnulloremptyStringFilter',
isnotnullorempty: 'isnotnulloremptyStringFilter',
}
},
messages: {
and: "And",
or: "Or",
info: "ShowItems"
}
},
dataBound: function () {
var filterCells = $(".k-filter-row").find("input");
filterCells.each(function (idx, cell) {
if ($(cell).data("role") == "autocomplete") {
var autocomplete = $(cell).data("kendoAutoComplete")
autocomplete.setOptions({ noDataTemplate: "" })
}
})
},
noRecords: {
template: '<h3>NoData</h3>'
},
sortable: true,
selectable: true,
reorderable: true,
columns: ColumnConfig,
columnMenu: {
messages: {
columns: "Columns",
filter: "Filter ",
sortAscending: "SortAscending",
sortDescending: "SortDescending"
}
},
columnReorder: function (e) {
var that = this;
console.log(that.columns);
setTimeout(function () {
$.ajax({
url: "/Common/ConfigureUserList/" + ListID,
type: "POST",
contentType: "application/json",
data: JSON.stringify(that.columns),
processData: false,
success: function (objStatus) {}
});
}, 5);
},
groupable: {
messages: {
empty: "GroupingMsg"
}
}
}).data("kendoGrid");
控制器代码
public JsonResult GetAllPartnersContactDetails1([DataSourceRequest]DataSourceRequest filter, int pageSize, int skip, int? page = null, string filterField = null, string filterValue = null)
{
var objPartnersModel = new PartnersModel();
var recordCount = objPartnersModel.GetAllPartnersContactDetails().Count();
var dataSet = objPartnersModel.GetAllPartnersContactDetails().Skip(skip).Take(pageSize).ToList();
DataSourceResult result = new DataSourceResult()
{
Data = dataSet,
Total = recordCount
};
return Json(result, JsonRequestBehavior.AllowGet);
}
请检查这对我来说很好用
只需为MVC应用程序添加此行。
type: "aspnetmvc-ajax"
$("#grid").kendoGrid({
ServerOperation: true,
dataSource: {
type: "aspnetmvc-ajax",
transport: {
read: {
url: '/Partners/GetAllPartnersContactDetails1', //using jsfiddle echo service to simulate JSON endpoint
type: "POST",
dataType: "json",
async: true,
//cache: false,
contentType: 'application/json',
data: function(e) {
debugger;
var grid = $("#grid").data("kendoGrid");
var $filter = new Array();
grid.dataSource.filter(e.filter);
console.log(e);
return e;
}
},
parameterMap: function(data, type) {
return kendo.stringify(data);
}
},
schema: {
data: function(result) {
return result.Data;
},
total: function(result) {
return result.Total;
}
},
type: "json",
serverPaging: true,
serverFiltering: true,
pageSize: 25,
},
filterable: {
mode: 'row',
operators: {
string: {
contains: "contains"
}
}
},
pageable: {
pageSizes: pageSizesArray,
numeric: false,
messages: {
itemsPerPage: "@Resources.Shared.ItemsPerPage",
display: "@Resources.Shared.PagingItemMsg",
empty: "@Resources.Shared.NoData"
}
//refresh: true,
},
height: $(window).height() * 85 / 100,
filterable: {
mode: "row",
operators: {
string: {
contains: 'containsStringFilter',
eq: 'eqStringFilter',
neq: 'neqStringFilter',
isnull: 'isnullStringFilter',
isnotnull: 'isnotnullStringFilter',
isempty: 'isemptyStringFilter',
isnotempty: 'isnotemptyStringFilter',
startswith: 'startswithStringFilter',
doesnotcontain: 'doesnotcontainStringFilter',
endswith: 'endswithStringFilter',
isnullorempty: 'isnulloremptyStringFilter',
isnotnullorempty: 'isnotnulloremptyStringFilter',
}
},
messages: {
and: "And",
or: "Or",
info: "ShowItems"
}
},
dataBound: function() {
var filterCells = $(".k-filter-row").find("input");
filterCells.each(function(idx, cell) {
if ($(cell).data("role") == "autocomplete") {
var autocomplete = $(cell).data("kendoAutoComplete")
autocomplete.setOptions({
noDataTemplate: ""
})
}
})
},
noRecords: {
template: '<h3>NoData</h3>'
},
sortable: true,
selectable: true,
reorderable: true,
columns: ColumnConfig,
columnMenu: {
messages: {
columns: "Columns",
filter: "Filter ",
sortAscending: "SortAscending",
sortDescending: "SortDescending"
}
},
columnReorder: function(e) {
var that = this;
console.log(that.columns);
setTimeout(function() {
$.ajax({
url: "/Common/ConfigureUserList/" + ListID,
type: "POST",
contentType: "application/json",
data: JSON.stringify(that.columns),
processData: false,
success: function(objStatus) {}
});
}, 5);
},
groupable: {
messages: {
empty: "GroupingMsg"
}
}
}).data("kendoGrid");