After researching for a while with no luck I finally found a solution. Here are the details.
Problem: I want to generate dynamic columns in the grid every refresh. Because my columns are based on an hour and date dimension which you would imagine are going to change every hour and hence would have a different name every time. However i still want to generate columns on the fly and show them with nice display labels as date
Solution: So i figured since I am getting Json data what should i do. Here is my solution.
Note that If try to pass pre-formatted string as the Key in JSon i.e. 03/01/2014. it would break the grid because the key in json has to comply with javascript variable naming conventions. So as a work around instead of passing the data string in json key i am passing something like "d03_01_2014". Once the gird is bound to the data i would loop through the columns collection of the kendo gird and rename/replace unwanted characters (i.e. 'd' and '_') with the ones i want.
below is the function that would create my grid
01.
function
createGrid10Days(data) {
02.
$(
"#grid10Days"
).kendoGrid({
03.
dataSource: {
04.
type:
"json"
,
05.
data: data,
06.
pageSize: 20
07.
},
08.
height: 605,
09.
scrollable:
false
,
10.
pageable: {
11.
input:
true
,
12.
numeric:
false
13.
},
14.
sortable:
true
15.
16.
});}
then upon document ready i can make calls to get JSon data and pass it to the create method above and do the renaming of columns afterwards as shown below.
//First Create My HTML grid the usual way. Pass in the JSON Data to the create grid method.
createGrid10Days(data);
//Right after the grid is created, rename the columns by looping through it
var
g = $(
"#grid10Days"
).data(
"kendoGrid"
);
for
(i = 0; i < g.columns.length ; i++)
{
var
oldFName = g.columns[i].field;
var
newFName = oldFName.replace(
"d"
,
""
);
newFName = newFName.split(
"_"
).join(
"/"
);
$(
"#grid10Days thead [data-field="
+ oldFName +
"] .k-link"
).html(newFName);
}
Hope this helps if you are same as my situation.
reference:
http://www.telerik.com/forums/how-do-you-change-the-column-header-text-in-javascript