This is a migrated thread and some comments may be shown as answers.

How to get grid selected row value ajax

4 Answers 1194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Santhosh
Top achievements
Rank 1
Santhosh asked on 11 Sep 2012, 05:39 AM
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

4 Answers, 1 is accepted

Sort by
0
Lakhani
Top achievements
Rank 1
answered on 29 Sep 2012, 12:50 PM
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;
}
0
Ravi
Top achievements
Rank 1
answered on 19 Oct 2012, 12:06 PM
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
0
Santhosh
Top achievements
Rank 1
answered on 20 Oct 2012, 08:33 AM
Hi Ravi

Try this method

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


thanks
Santhosh
0
Ravi
Top achievements
Rank 1
answered on 22 Oct 2012, 03:18 AM
Thanks Santosh

Regards,
Ravi
Tags
Grid
Asked by
Santhosh
Top achievements
Rank 1
Answers by
Lakhani
Top achievements
Rank 1
Ravi
Top achievements
Rank 1
Santhosh
Top achievements
Rank 1
Share this question
or