以编程方式选择Kendo网格行 [英] Select programmatically Kendo grid row

查看:89
本文介绍了以编程方式选择Kendo网格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了类似标题的帖子,但我仍然无法解决我的问题。肯定我做错了。

I found posts with similar titles but I still cannot resolve my issue. Definitely I am doing something wrong.

在Kendo网格配置中有一些功能,它采用上下文(网格)和读取所选行:

In Kendo grid configuration have some function which take context (grid) and read selected row:

change: function (e) {
            refresh(this);
        }

这是我配置更改事件的方式。

This is how I configured "change" event.

在功能刷新(网格)中,我按以下方式选择了行:

In function "refresh(grid)" I am getting selected row on following way:

    refresh: function (grid) {        
    var selectedRows = grid.select();
    var selectedRow = grid.dataItem(selectedRows[0]);
    var id = selectedRow.Id;
}

当我手动选择网格行时,这种方法非常有效。但是当我以编程方式选择行时,selectedRow变量为null。

This approach works perfect when I select grid row manually. But when I select row programatically "selectedRow" variable is null.

我在以下方式中以编程方式选择:

I am selecting programatically on following way:

var grid = $("#grid").data("kendoGrid"); 
var rows = grid.dataSource.data(); 
var row = rows[rows.length - 1]; 
grid.select(row);

正如我上面的遗憾,在之前的刷新(网格)方法变量中,selectedRow将为null。

As I sad in above, in previous "refresh(grid)" method variable selectedRow will be null.

有人对此有一些看法吗?为什么会这样?

Does anybody have some opinion about that? Why is it happened?

谢谢

推荐答案

根据Grid文档select方法接受string参数(选择器)或jQuery元素。这就是为什么如果您需要正确选择行,您应修改当前代码,如下所示:

According to the Grid documentation the "select" method accepts "string" parameter (selector) or jQuery element. That why if you need to correctly select the row you should modify your current code as follows:

var grid = $("#grid").data("kendoGrid"); 

//if you are using the "pageable" option of the grid
//you should get the visible rows using the .view() method
var models = grid.dataSource.data();

var model = models[models.length - 1]; 
var lastRowUid = model.uid;

//find the target row element:
var row = grid.table.find("[data-uid=" + lastRowUid + "]");

grid.select(row);

这篇关于以编程方式选择Kendo网格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆