test
test

Reputation: 91

How to select kendo grid row if that row is not present on first page of the kendo grid./

Tried to select a kendo grid row in dataBound (Note: that row is not on first page of the grid) but it didn't selected 3rd page row.

dataBound: function(e) {
            if (id!== "" && id!== undefined && id!== null) {
                var grid = e.sender;
                grid.select("tr:contains('" + id + "')");
            }
        },

Here id is in the page URL and getting ids value like below: and that will get passed in dataBound id var.

id = $location.search().id;

Any ideas how i can select the 3rd page row? Above logic works for the rows that are present on first page of the kendo grid

When tried selecting 3rd page row, it stays at first page only with nothing selected since that row belongs to third page of the grid.

Upvotes: 0

Views: 1472

Answers (1)

test
test

Reputation: 91

Below function is for finding dataItem and selection of any page row.

Var initial prevents the databound to get called after first call.

function findDataItem(ragGrid, dataItem) {
        initial = true;
        var ds = ragGrid.dataSource;
        var view = window.kendo.data.Query.process(ds.data(), {
            filter: ds.filter(),
            sort: ds.sort()
        }).data;
        var index = -1;
        for (var x = 0; x < view.length; x++) {
            if (view[x].Id == dataItem.Id) {
                index = x;
                break;
            }
        }
        if (index === -1) {
            return;
        }
        var page = Math.floor(index / ragGrid.dataSource.pageSize());
        var targetIndex = index - (page * ragGrid.dataSource.pageSize())+ 1;
        ragGrid.dataSource.page(++page);
        var row = $("#ragGrid").find("tr:eq(" + targetIndex + ")");
        ragGrid.select(row);
    }

Here is the dataBound function and calling findDataItem in dataBound first call.

  dataBound: function (e) {
            if (id !== "" && id !== undefined && id !== null) {
                if (!initial){
                var grid = e.sender;
                var data = grid.dataSource.data();
                var res = $.grep(data, function (d) {
                    return d.Id == id;
                });
                findDataItem(grid, res[0]);
                }
            }
        },

Upvotes: 1

Related Questions