Split/Capitalize Auto Generated Column Titles

4 posts, 0 answers
  1. Rob
    Rob avatar
    3 posts
    Member since:
    Sep 2015

    Posted 09 Oct 2015 Link to this post

    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

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 13 Oct 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Rob
    Rob avatar
    3 posts
    Member since:
    Sep 2015

    Posted 13 Oct 2015 in reply to Nikolay Rusev Link to this post

    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

  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 15 Oct 2015 Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready