Kendo Grid

1 Answer 99 Views
Grid
Raymond
Top achievements
Rank 1
Veteran
Raymond asked on 21 Apr 2023, 01:20 PM

hi, I have created a grid that works 'fine' and display one line as supposed, 

        @(Html.Kendo().Grid<ESACatalog.Models.tb_Part>()
    .Name("gridPart")
    .Columns(columns => {
        columns.Bound(p => p.PartID).Width(150);
        columns.Bound(p => p.ClassID);
        columns.Bound(p => p.PartListPrice).Width(100).Title("List Price");
        columns.Bound(p => p.PartDesc).Title("Description");
    })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Get_Part", "Home").Data("getParameter")))
        )

 

I need now to read the value of column ClassID to reuse it so i tried the following code

var grid = $("#gridPart").data("kendoGrid");

grid.bind("change", function(e) {
    var dataItem = grid.dataSource.view()[0];
    if (dataItem) {
        var value = dataItem.columnName;
        console.log(value);
    }
});

but got a message as unassigned

I would really appreciate any help

thanks
Ray

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 25 Apr 2023, 07:39 AM

Hi Raymond,

Thank you for the code snippets and details provided.

As I can see in the code, the "columnName" is used, but never defined.

In order to get the needed value, I would recommend using the "document.ready" jQuery Event, or the DataBound event of the Grid. In the Event handler scope, use the following:

var grid = $("#grid").data("kendoGrid");
var dataItem = grid.dataItem("tbody tr:eq(0)");
The following article describes the approach to getting the first dataItem:

I hope this information helps. Let me know if further information or assistance is needed.

Kind Regards,
Anton Mironov
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
Raymond
Top achievements
Rank 1
Veteran
Answers by
Anton Mironov
Telerik team
Share this question
or