Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get row state (selected or not) in kendo grid

I have a kendo ui grid with multiple selected rows and I need to get all rows and there state (selected or not) for an ajax request. How I can do that ? this is my code, thanking you :

 function () {
var entityGrid = $("#archivesGrid").data("kendoGrid");
                var rows = entityGrid.dataSource.data();
                var totalItem = rows.length;
                var items = [];
                for(var i = 0; i < totalItem; i++) {
                    var currentItem = rows[i];
                    items.push({
                        name: currentItem.DataAddress.Address,
                        selected: true // Attributes ?
                    });
                }
        }

I know how I can have selected rows with select() but there isn't an attribute or something in dataItem to know if it select or not ?

like image 550
kleww Avatar asked Jan 28 '26 20:01

kleww


1 Answers

To get all rows and their states you could query for .k-state-selected. Something like the below will return the uid and it's state:

function getStates() {
    var rowStates = {};
    $("#archivesGrid  tbody").find('tr').each(
    function () {
        var id = $(this).data("uid");
        var selected = $(this).hasClass('k-state-selected');
        rowStates[id] = selected;
        }
    );
    return rowStates;
};
like image 58
MattOG Avatar answered Jan 31 '26 10:01

MattOG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!