This is a migrated thread and some comments may be shown as answers.

Ajax GET request error when grid has certain characters in column names

4 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 11 Oct 2013, 05:00 PM
Hi. I've been trying to figure out why my DataTable bound grid (with dynamic columns and Ajax data source) was erroring whenever I clicked a column heading to sort it. This has been driving me crazy as my view and controller code is very similar to the binding to data table sample code you provide.

I finally discovered the problem occurs whenever a column has certain characters in the column name (e.g. a space, a period or a hash character). If one of these characters is present the request becomes a GET rather than a POST which results in a 404 error as JSON results are not permitted via GET by default.

Please let me know how I can have column names with these characters as they are required for our column names.  Thanks!

View code:
@(Html.Kendo().Grid(Model)
           .Name("grid")
           .Columns(columns =>
           {
               foreach (System.Data.DataColumn column in Model.Columns)
               {
                   columns.Bound(column.ColumnName);
               }
           })
           .Pageable()
           .Sortable()
           .DataSource(dataSource => dataSource
               .Ajax()
               .Model(model =>
               {
                   foreach (System.Data.DataColumn column in Model.Columns)
                   {
                       model.Field(column.ColumnName, column.DataType);
                   }
               })
               .Read(read => read.Action("Read", "Reports"))
           )
       )
Controller code:
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
        {
            DataTable products = Products();
 
            return Json(products.ToDataSourceResult(request));
        }

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Oct 2013, 07:08 AM
Hi Ian,

 Currently the Kendo UI Grid doesn't support columns bound to fields which are invalid JavaScript identifiers. A valid column name should start with a letter and contain only other letters, numbers, "_" and "$". There is no workaround which would enable such support.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ian
Top achievements
Rank 1
answered on 14 Oct 2013, 09:55 AM
Thanks for the reply. I actually don't care what the columns are called but I do need to have those characters in the column titles. I guess I could store a JavaScript-friendly column name and have a display name for each column and use the Title method on the column builder to set the title correctly. Alternatively I could create encode/decode functions for this mapping. Will have a think.
0
Accepted
Atanas Korchev
Telerik team
answered on 14 Oct 2013, 10:38 AM
Hi Ian,

 Indeed you can only set the Title to a user-friendly string with spaces etc. Only the bound field (DataTable column name) should follow the described rules.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Andreas Mildenberger
Top achievements
Rank 1
answered on 10 Jul 2015, 12:14 PM

Hello,

 

is that issue meanwhile improved as i want to use # ...

Tags
Grid
Asked by
Ian
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ian
Top achievements
Rank 1
Andreas Mildenberger
Top achievements
Rank 1
Share this question
or