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

Split/Capitalize Auto Generated Column Titles

3 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 09 Oct 2015, 09:02 AM

Hi,

 I have probably missed something really obvious, but I just can't seem to find the right property.

 I have a Grid bound to an OData source from which I am auto generating the columns. When this happens the column titles are not split around capital letters so they are readable unlike when they are bound individually. I tried using a column build action to set the titles of the columns, but it doesn't seem to work... unless I am doing something not quite right.

 A bit of example code here (I have just tried to change the column name to a set value, but it doesnt work when I try to split the column member name either)

@(Html.Kendo().Grid<dynamic>()
      .Name(Model.Name)
      .Columns(columns =>
      {
          //columns.AutoGenerate(true);
          //columns.AutoGenerate(col => col.Title = col.Member.SplitPascalCase());
          columns.AutoGenerate(col => col.Title = "COLUMN NAME");
      })
      .DataSource(dataSource => dataSource
          .Custom()
          .Type("odata")
          .Schema(schema =>
          {
          schema.Data("value")
              .Total
              (
                    @<text>
                        function total(data)
                        {
                        return data["odata.count"];
                        }
                    </text>
                );
          })
          .Transport(transport =>
          {
              transport.Read(read => read.Url(Model.ODataPath).DataType("json"));
          }
          )
          .PageSize(Model.PageSize)
          .ServerPaging(true)
          .ServerSorting(true)
          .ServerFiltering(true)
      )

thanks,

 Rob

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 13 Oct 2015, 08:38 AM

Hello Rob,

 

This is because you have defined grid model as dynamic type `Html.Kendo().Grid<dynamic>()`.  There isn't a way to extract the actual, run-time, type from it as the widget is bound on client through AJAX request. Thus auto columns cannot extract the type info.

 

Regards,
Nikolay Rusev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Rob
Top achievements
Rank 1
answered on 13 Oct 2015, 09:58 AM

Thanks Nikolay,

 I am using the dynamic type as I want to use the same Grid code for multiple OData data sources. I have worked round this by specifying the column names in my Model, but would prefer not to have to do that if possible, can you suggest another approach to this problem?

 thanks,

Rob

0
Nikolay Rusev
Telerik team
answered on 15 Oct 2015, 07:20 AM

Hello Rob,

 

This is not possible if dynamic is used as generic type for the Grid. If you inspect the serialized initialization script of the widget you will see that there isn't any columns inferred from that model.

 

The only way is to specify concrete model type.

 

For example Html.Kendo().Grid<CustomerViewModel>()

 

Regards,
Nikolay Rusev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Rob
Top achievements
Rank 1
Share this question
or