【发布时间】:2014-02-11 01:28:45
【问题描述】:
是否可以枚举来自数据库表的网格列,例如(标题和宽度)?
【问题讨论】:
标签: kendo-ui kendo-grid kendo-asp.net-mvc
是否可以枚举来自数据库表的网格列,例如(标题和宽度)?
【问题讨论】:
标签: kendo-ui kendo-grid kendo-asp.net-mvc
您需要为此进行 ajax 调用。从表中派生列名,然后您可以进行修改。
例如
$.ajax({
url:actionUrl, //Url of the Method for fetching names of the columns and its count
success: function(result){
for (var i = 0; i < result.columnsCount; i++) { //running the loop based on number of columns needed
columns.push({
field: result.columnName, //set the columnNames from the Db as field
title: result.Header //specifying the columns title
});
}
}
});
【讨论】:
您可以尝试以下方法:
$(document).ready(function() {
var model = kendo.observable({
gridRows: []
});
var columns = [];
for (var i = 0; i < 4; i++) {
var entryIndex = "entries[" + i + "]";
columns.push({
field: i,
title: "Column " + i
});
}
var configuration = {
resizable: true,
columns: columns
};
var timeEditGrid = $("#grid").kendoGrid(configuration).data("kendoGrid");
kendo.bind($('#example'), model);
});
【讨论】: