Error when attempting to select a grid row using JavaScript function

1 Answer 84 Views
Grid
Mark
Top achievements
Rank 1
Mark asked on 11 Oct 2022, 05:10 PM

When I click my (test) button to select a row (with Id = 2) in my grid, I get the error:

"Uncaught TypeError: Cannot read properties of undefined (reading 'get') at selectRowById".

Here is my function:

  function selectRowById(id) {
        var grid = $("#grid").data("kendoGrid")
        var dataItem = grid.dataSource.get(id);
        var dataItemUID = dataItem.get("uid"); 
        var tableRow = $("[data-uid='" + dataItemUID + "']");
        grid.select(tableRow);
    }

Here is my grid:

@(Html.Kendo().Grid<Document>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.DocumentId).Title("Doc Id").Filterable(false).Width(90);
        columns.Bound(p => p.StorageContainer).Title("Container").Width(100);
        columns.Bound(p => p.FileName).Width(350);
        columns.Bound(p => p.DocStatus).Width(125);
        columns.Bound(p => p.FileSize).Width(125).HtmlAttributes(new { @style = "text-align: right" });
        columns.Bound(p => p.ClientDocumentId).Title("Client Doc Id").Width(200);
        columns.Bound(p => p.CreateDate).Format("{0:MM/dd/yyyy}").Width(130);
        columns.Command(command => { command.Edit().Text(" "); command.Destroy().Text(" "); }).Width(150);
    })
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Selectable(selectable => selectable
        .Mode(GridSelectionMode.Multiple)
        .Type(GridSelectionType.Row))
    .Pageable()
    .Resizable(resize => resize.Columns(true))
    .Pageable()
    .Sortable()
    .Scrollable()
    .Reorderable(reorder => reorder.Columns(true))
    .Filterable()
    //.Groupable()
    .HtmlAttributes(new { style = "height:650px;" })
    .DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .Model(model =>
    {
        model.Id(p => p.DocumentId);
        model.Field(p => p.DocumentId).Editable(false);
        model.Field(p => p.CreateDate).Editable(false);
    })

    .Read(read => read.Action("Read", "Document").Data("getApplicationId"))
    .Create(update => update.Action("Create", "Document"))
    .Update(update => update.Action("Update", "Document"))
    .Destroy(update => update.Action("Delete", "Document"))
    )
)

 

Any help would be greatly appreciated. Thanks.

Mark

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 14 Oct 2022, 09:51 AM

Hi Mark,

I noticed that there is not a Telerik UI for ASP.NET Core license associated with your account which limits the availability of our support services for the product. In this regard, It is recommended that you either purchase or renew your license in order to gain access to the latest updates, fixes, features, and support regarding the Telerik UI for ASP.NET Core components. More information regarding the currently available plans can be reviewed here:

That being said, I did not see anything obvious within the Grid's configuration that could potentially cause the reported behavior.

Thus, based on the provided details I created a Telerik REPL example that tackles a scenario that includes an external button with a default argument passed for its click event. But it seems that the Grid is selecting the specified row successfully on my end. Here is the exemplary configuration:

<button onclick="selectRowById(2)">Select Row By 2 ID</button>


<script type="text/javascript">
  function selectRowById(id) {
        var grid = $("#grid").data("kendoGrid")
        var dataItem = grid.dataSource.get(id);
        var dataItemUID = dataItem.get("uid"); 
        var tableRow = $("[data-uid='" + dataItemUID + "']");
        grid.select(tableRow);
    }
 </script>

I may be missing something pivotal within your currently implemented scenario. Thus, could you please consider sharing more details as to how the id is passed within the click handler and that of the "test" button's configuration?

This will help me get a better understanding of the current implementation you have utilized on your end.

Looking forward to hearing back from you.

Kind Regards,
Alexander
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Mark
Top achievements
Rank 1
commented on 16 Oct 2022, 02:55 PM

Alexander:

Thanks very much, that works. And I am trying to get my license renewed soon.

Mark

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or