I have Kendo MVC grid and the columns of the grid are dynamic based on the model that gets filled on the datasource read method. I need to loop through the dynamic columns to generate it on the grid.
I have kept autobind(false) and have called the read method on button click. But when the kendo grid columns gets generated the list on which i am looping through has 0 count as that gets filled after the read method. Columns generation is happening before the read method. I need to regenerate columns after the read method. grid.refresh() is not working for me.
.AutoBind(false)
.Columns(columns =>
{
columns.Bound(x => x.Name).Title("Name");
for (int i = 0; i < Model.obj.lstdateValueDicts.Count; i++)
{
var index = i;
columns.Template(@<text>@Convert.ToString(Model.obj.lstdateValueDicts[index])</text>).Title(Model.obj.lstdateValueDicts[i].Value);
}
})
Script:(on button click)
var grid = $('#FlowSheetsGrid').data('kendoGrid');
grid.dataSource.read();
debugger;
grid.refresh();
$("#FlowSheetSearchResults").show();
I expect the columns to get regenerated after the read method is over so the the list on which i am trying to generate the columns will get some count and it will get generated. Right now its getting 0 count and thus columns in loop does not get generated.