我使用Kendo指令启动了一个Kendo Grid。如何捕获网格的keydown / keypress事件?我的最终目标是根据另一列的用户输入填充网格列。例如,在输入第一个名称时填充电话号码。为此,我相信我必须使用Kendo Grid编辑和按键事件并对用户输入进行搜索,除非有更好的方法。这可能吗?
这是我初始化网格的方式:
<section id="dashboard-view" class="mainbar" data-ng-controller="dashboard as vm">
....
<div kendo-grid="vm.testGrid" k-options="vm.testGridOptions" k-rebind="vm.testGridDataSource.data" k-on-edit="vm.onEdit(kendoEvent)"></div>
....
</section>
我的JavaScript文件中定义的选项:
vm.testGridOptions = {
columns: [
{ field: "Id", title: "ID" },
{ field: "FirstName", title: "First Name" },
{ field: "LastName", title: "Last Name" },
{ field: "Phone", title: "Phone" },
{ command: ["destroy"] }
],
toolbar: ["create", "save", "cancel"],
dataSource: vm.testGridDataSource,
editable: {
createAt: "bottom"
},
height: 400,
autoBind: false
};
vm.onEdit = function (e) {
//if grid column == Id && keypressed == Tab key
//search
};
网格处于批量编辑模式。
答案 0 :(得分:1)
您可以根据索引查找当前列/字段名称。然后过滤它旁边的列中的下拉列表:(这只是一个示例代码,请用您的代码替换DOM ID)
vm.onEdit = function (e) {
var header = vm.thead;//grid header
var index = vm.cellIndex(e.container);//current cell index
var th = $(header).find("th").eq(index);
var colName = $(th).data("field");//fieldname for current cell
var dataItem = e.model;//row model
if(colName=='LastName')
{
var phoneDropDown = e.container.find("#PhoneDropDownId").data("kendoDropDownList");
if (phoneDropDown) {
phoneDropDown.dataSource.filter({ field: "Phone", operator: "eq", value: e.model.LastName });
}
}
};
答案 1 :(得分:0)
由于Kendo Grid没有本机事件,我使用了JQuery onBlur事件。
vm.onEdit = function (e) {
alert("Edit event fired");
$('input.k-input.k-textbox').blur(function (f) {
alert("Blur event fired");
}
};