Question

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 ?

Was it helpful?

Solution

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;
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top