0
votes

I have a kendo grid in my project and a custom button in that grid. I tried to get row data when I click the button. But javascript code gives me error which is:

"Javascript runtime error: Unable to get property "dataItem" of undefined or null referance"

My grid code :

@model IEnumerable<SalePortal.ServiceReference.Product>

    @{
        ViewBag.Title = "GetProduct";
    }


    @(Html.Kendo().Grid<SalePortal.ServiceReference.Product>()
    .Name("Grid")
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("GetProduct", "Home"))
        )
    .Columns(columns =>
        {
            columns.Bound(product => product.pID);
            columns.Bound(product => product.productName);
            columns.Bound(product => product.productPrice);
            columns.Command(command => command.Custom("Buy").Click("Sale"));
        })

    )

My javascript code :

    <script type="text/javascript">

    function Sale() {

        var gridE = $("#kendoo").data("kendoGrid");
        var selectedItem = gridE.dataItem(gridE.select());  //Error here!!!

        alert(selectedItem);

</script>
1

1 Answers

0
votes

You need to specify Grid Name/Id when fetching data through dataItem.

Try this:

 <script type="text/javascript">

function Sale() {

    var gridE = $("#Grid").data("kendoGrid");
    var selectedItem = gridE.select();  //Updated here!!!
    var dataItemSelectedData = gridE.dataItem(selectedItem); //Updated here!!!

    alert(dataItemSelectedData); //Updated here!!!

</script>