Kendo Grid排序无效。 我的守则如下:
$("#divTableContent").kendoGrid({
pageable: {
input: true, //To input the pagenum
numeric: false
},
dataBound: onDataBoundGrid,
resizable: false,
filterable: {
filter: true,
extra: false,
operators: {
string: {
eq: "Is equal to",
contains: "Contains",
}
}
},
sortable: {
mode: "single",
allowUnsort: true
},
dataSource: {
serverPaging: true,
serverSorting: true,
serverFiltering: true,
我的数据绑定功能是
function onDataBoundGrid(e) {
var gridColumns = [];
var tableContentGrid = $("#divTableContent").data("kendoGrid");
debugger;
for (var i = 0; i < tableContentGrid.columns.length; i++) {
if (tableContentGrid.columns[i].field.indexOf("_") >= 0) {
var column = $.grep(seperatedColumnHeaders, function (item) {
return item == tableContentGrid.columns[i].field.replace(/_/g, ' ');
});
if (column.length > 0) {
// Pushing the field and title
gridColumns.push({ 'field': tableContentGrid.columns[i].field, 'title': tableContentGrid.columns[i].field.replace(/_/g, ' ') });
}
var column1 = $.grep(seperatedColumnHeaders, function (item) {
return item == tableContentGrid.columns[i].field;
});
if (column1.length > 0) {
// Pushing the field and title
gridColumns.push({ 'field': tableContentGrid.columns[i].field, 'title': tableContentGrid.columns[i].field.replace(/__/g, ',')} );
}
if (column.length == 0 && column1.length == 0) {
gridColumns.push({ 'field': tableContentGridHeaders[i], 'title': tableContentGridHeaders[i] });
}
} else {
// Pushing the field and title
gridColumns.push({ 'field': tableContentGrid.columns[i].field, 'title': tableContentGrid.columns[i].field });
}
}
// Replacing the old grid columns with new grid columns
tableContentGrid._columns(gridColumns);
// Removing the old grid titles
tableContentGrid.thead.empty();
// It will replace with new grid titles
tableContentGrid._thead();
}
我们正在动态创建列,并且为了删除标题中的空格,我编写了数据绑定函数。如果我删除数据绑定排序正在工作。如果数据绑定在那里排序不起作用,并且每次它都会像升序那样进入控制器。
答案 0 :(得分:0)
Kendo的网格作为_columns属性,但前面的下划线意味着它仅用于内部目的。它不受剑道支持,必须小心使用,以避免在其他地方造成问题。
据我所知,加载后无法更改网格的列。必须在网格初始化之前完成添加,更改和删除列。但是,如果需要,您仍然可以直接在DOM中更改列的标题。
您的示例中未指定dataSource以及向网格提供数据,架构和列的方式...如果您可以在初始化网格之前设法获取所有列规范,那么您将能够在此过程的早期实现onDataBoundGrid函数的逻辑。