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

Grid DataKeys Setup

3 Answers 559 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 14 Sep 2012, 06:48 AM
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.

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 14 Sep 2012, 07:46 AM
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!
1
Léo
Top achievements
Rank 1
answered on 08 Mar 2021, 07:47 AM

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?)

0
Tsvetomir
Telerik team
answered on 10 Mar 2021, 01:52 PM

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.

Tags
Grid
Asked by
Sam
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Léo
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or