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

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

问题描述

我找到了标题相似的帖子,但我仍然无法解决我的问题.肯定是我做错了什么.

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"变量为空.

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 变量将为空.

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" 方法接受字符串"参数(选择器)或 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);

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

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