Reputation: 292
I am using kendoUI grid.I want to display column names dynamically.can you tell me how to display columns dynamically
var columns = [];
columns.push({ field: "prj_project_time_entry_start_date", title: "period" });
for (var i = 0; i < json.length; i++) {
var entryIndex = "entries[" + i + "]";
columns.push({
field: entryIndex,
title: "" + json[i].usr_bio_first_name
});
}
var configuration = {
editable: true,
sortable: true,
scrollable: false,
columns: columns
};
var timeGrid = $("#grid").kendoGrid(configuration).data("kendoGrid");
This is how I am able to display columns dynamically.For displaying the records in the grid I used like
$("#grid").kendoGrid({ dataSource: gridDataSource,
selectable: "multiple",
sortable: false,
refresh: true,
navigatable: false
});
If i give like this,all the values in my controller(query) are displaying with out depending upon the column names. Thanks.
Upvotes: 0
Views: 4756
Reputation: 20203
What do you mean by display column names dynamically?
Basically to bind to a collection of dynamic objects, you can use the approach in this code library project. If you want to change the name of the column, you should use the Title method (which accepts a string as parameter).
columns.Bound("ProductID").Title("Column name Here");
Upvotes: 3