Grid DataKeys Setup

4 posts, 0 answers
  1. Sam
    Sam avatar
    22 posts
    Member since:
    May 2012

    Posted 14 Sep 2012 Link to this post

    good morning everyone,

    I am currently using the licensed version of Kendo UI Complete for ASP.NET MVC (Q2 2012) and trying to figure out if the Kendo UI Grid has something similar to the DataKeys method in the Telerik Extensions for ASP.NET MVC Grid?

    Before this, I was using the licensed version of Telerik Extensions for ASP.NET MVC.  Below is the code I had for it.  You'll notice, there is a "DataKeys" method which I can associate the "Id" property of the Model, to each row of the Grid. 

    @{Html.Telerik().Grid(Model)
        .Name("grdAllUsers")
        .DataKeys(keys => keys.Add(k =>
            k.Id)
        )
        .Columns(columns =>
        {
            columns.Bound(o => o.FirstName)
                .Width(150);
            columns.Bound(o => o.LastName)
                .Width(150);
            columns.Bound(o => o.EmailAddress)
                .Width(200);
            .Width(70)
            .HtmlAttributes(new { style = "text-align:center" });
        })
        .NoRecordsTemplate(@<text>No User records to display.</text>)
        .Pageable(paging =>
            paging.PageSize(15)
        )
        .Sortable()
        .Filterable()
        .Render();
    }


    Is there something similar in the Kendo UI Grid???  Below is my current Kendo UI Grid.

    @{Html.Kendo().Grid(Model)
        .Name("grdAllUsers")
        .Columns(columns =>
        {
            columns.Bound(o => o.FirstName)
                .Width(150);
            columns.Bound(o => o.LastName)
                .Width(150);
            columns.Bound(o => o.EmailAddress)
                .Width(200);
            .Width(70)
            .HtmlAttributes(new { style = "text-align:center" });
        })
        .Pageable(paging =>
            paging.PageSize(15)
        )
        .Sortable()
        .Filterable()
        .Render();
    }

    Thank you very much for your help.
  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 14 Sep 2012 Link to this post

    Hi Sam,

    DataKey can be set through DataSource Model declaration. Please refer to this online help article for additional details.

    All the best,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Léo
    Léo avatar
    1 posts
    Member since:
    Sep 2020

    Posted 08 Mar in reply to Rosen Link to this post

    You say DataKey can be set through DataSource Model declaration, but there are several differences with the Telerik DataKeys method:

    - with telerik, you could set several keyS
    - with telerik, you could retrieve these fields with javascript: `$("#dataGrid").data("tGrid").dataKeys`

    I don't really get why you didn't keep this feature when moving from Telerik to Kendo (unless you provided another way to achieve this?)

  4. Tsvetomir
    Admin
    Tsvetomir avatar
    837 posts

    Posted 10 Mar Link to this post

    Hi Léo,

    It is correct that there is a single ID field that can be specified. Indeed, the grid would not know which of the fields are to be used and the best practices show that there should be only a single ID (apart from the grid, it is commonly acknowledged to have a single ID).

    As per the retrieval, you could access it as follows:

    $($0).getKendoGrid().dataSource.options.schema.model.id
    

    Let me know if additional information is needed.

     

    Regards,
    Tsvetomir
    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.

Back to Top