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

我只是一个虾纸丫 提交于 2019-12-13 08:49:50

问题


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.


回答1:


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]);
                }
            }
        },


来源:https://stackoverflow.com/questions/34655978/how-to-select-kendo-grid-row-if-that-row-is-not-present-on-first-page-of-the-ken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!