数据库驱动的Kendo Grid专栏

时间:2014-02-11 01:28:45

标签: kendo-ui kendo-grid kendo-asp.net-mvc

是否可以枚举来自数据库表的网格列,例如(标题和宽度)?

2 个答案:

答案 0 :(得分:0)

您可以尝试以下操作:

$(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);
}); 

http://jsfiddle.net/4sM7g/

答案 1 :(得分:0)

您需要为此进行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
            }); 
        }
    } 
});