简体   繁体   中英

asp.net Kendo, couldn't get selected row datas

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM