Just getting started with Kendo Grid - below is my VB.NET razor code (I know, I know) working against a System.Data.DataTable for a model. The DataTable contains columns in it where some of the ColumnNames have spaces. The web page successfully renders my table, but, it errors due to the Kendo's row template, it seems. Dim mainGrid = Html.Kendo().Grid(Model.MainTable) _ .Name("Grid") _ .Columns(Sub(cols) cols.AutoGenerate(True) End Sub) _ .DataSource(Sub(dSource) dSource.Ajax() End Sub) _ .Pageable() _ .Sortable() _ .Filterable()
Hi Brian,
The Grid component and also the DataSource were designed in a way that spaces in property names are not available out of the box. This is because the components can be used in a vast number of scenarios and should be able to handle all of them.
That said, if spaces are available you can use the described approach.
Regards,
Viktor Tachev
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
I'm also finding if I go into the src javascript for kendo.web.js (scroll down to line 7594) and I add this line to detect spaces, my DataTable driven Kendo Grids render a lot more happily in MSIE and Firefox //add these 2 lines after var fromName - i.e. after line 7594 if (field.indexOf(" ") > -1) field = "['" + field + "']";
If I supply my own ClientRowTemplate, then it starts to work better- IMHO this template should be the standard OOTB behavior.. as I belive this style of template logic will work across the board. Dim sb As New StringBuilder("<tr data-uid=""#=data.uid#"" role='row'>") For Each c In Model.MainTable.Columns sb.AppendFormat("<td role='gridcell'>#:data['{0}']==null?'':data['{0}']#</td>", c.ColumnName) Next sb.AppendLine("</tr>")
I came across this snippet for how to do client script of field names with spaces http://jsbin.com/evapes/3/edit and will see if this can be obtained using the server wrapper somehow
As I continue experimentation, it seems to be a limitation in regard to how a System.Data.DataTable can be bound (i.e. - not specific to AutoGenerateColumns) - I have highly engineered T-SQL statements producing data with specific column names (using square brackets allows returned column names to have spaces in it) and those columns are simply coming straight into my System.Data.DataTable as-is.. but the Kendo UI Grid ASP.NET server wrapper cannot seem to parse it successfully.