How to get grid selected row value ajax

5 posts, 0 answers
  1. Santhosh
    Santhosh avatar
    7 posts
    Member since:
    Jul 2012

    Posted 11 Sep 2012 Link to this post

    How to get the row value on Kendo grid row selection change.  I used a ajax method to bind the Kendo grid. 

    @(Html.Kendo().Grid<OnlineAB.Models.GoodsServiceModel>()
                .Name("GSSrcGrid")
                .Columns(columns =>
                {
                    columns.Bound(gs => gs.ID).Visible(false);
                    columns.Bound(gs => gs.GSPrice).Groupable(false).Width(100);
                    columns.Bound(gs => gs.GSTime).Width(100);
                    columns.Bound(gs => gs.GSDescription).Width(200);
                    columns.Bound(gs => gs.GSTitle).Width(150);
                    columns.Bound(gs => gs.GSCode).Width(120);
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("GetGoodsandService", "GS")
                        .Data("GetParam"))
                    .ServerOperation(false)
                )
                .Sortable()
                .Scrollable()
                .Filterable()
                .RowAction(row => row.HtmlAttributes.Add("data-id", row.DataItem.ID))
                .Selectable(s => s.Mode(GridSelectionMode.Single))
                .Events(events => events.Change("GSSelectionChange"))
        )

    and js code snippet

    function GSSelectionChange() {
             var gsgrid = $('#GSSrcGrid').data('kendoGrid');
            var goods = gsgrid.select();
            var goodsID = goods.data("id");
            alert(goodsID);
    }

    goodsID always return undefined.  Whats the wrong with this.


    thanks
    Santhosh
  2. Lakhani
    Lakhani avatar
    5 posts
    Member since:
    Jun 2012

    Posted 29 Sep 2012 Link to this post

    Change your GSSelectionChange Like as bellow
    function GSSelectionChange() {
    var selectedrow = $("#GSSrcGrid").find("tbody tr.k-state-selected");
       var goods = $('#GSSrcGrid').data("kendoGrid").dataItem(selectedrow);
       var goodsjson = goods.toJSON();
       var goodsID = goodsjson.id;
    }
  3. Kendo UI is VS 2017 Ready
  4. Ravi
    Ravi avatar
    17 posts
    Member since:
    Oct 2012

    Posted 19 Oct 2012 Link to this post

    Hello,

    I am handling the same scenerio, So i have used your code sample.

    function GSSelectionChange() {
    var selectedrow = $("#GSSrcGrid").find("tbody tr.k-state-selected");
       var goods = $('#GSSrcGrid').data("kendoGrid").dataItem(selectedrow);
       var goodsjson = goods.toJSON();
       var goodsID = goodsjson.id;
    }

    It returns the object for Selectedrow
     
    but to execute the below line of code 
       var goods = $('#GSSrcGrid').data("kendoGrid").dataItem(selectedrow);
    it thow the error "Microsoft JScript runtime error: 'this._data' is null or not an object".

    Could you please help me.

    Regards,
    Ravi
  5. Santhosh
    Santhosh avatar
    7 posts
    Member since:
    Jul 2012

    Posted 20 Oct 2012 Link to this post

    Hi Ravi

    Try this method

    function GSSelectionChange() {
            var goods = this.select(),
                goodsID = this.dataItem(goods).ID;
    ..
    }


    thanks
    Santhosh
  6. Ravi
    Ravi avatar
    17 posts
    Member since:
    Oct 2012

    Posted 21 Oct 2012 Link to this post

    Thanks Santosh

    Regards,
    Ravi
Back to Top
Kendo UI is VS 2017 Ready