Kendo Grid:在组合框选择上设置“模型"字段会中断组合框的向上/向下箭头滚动 [英] Kendo Grid: Setting Model fields on combox selection breaks the combobox up/down arrow scrolling

查看:63
本文介绍了Kendo Grid:在组合框选择上设置“模型"字段会中断组合框的向上/向下箭头滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自另一个

this follows in from another post to do with setting a grid's selected fields when we have a data source field (and combo fields) with a json object (as opposed to a simple string).

因此,如果我们查看以下combox的change事件处理程序...

So if we look at the change event handler for the following combox...

function createCombo(container, options, data) {
  var input = $('<input name="' + options.field + '" />')
  input.appendTo(container)
  input.kendoComboBox({
  autoBind: true,
  filter: "contains",
  placeholder: "select...",
  suggest: true,
  dataTextField: "display",
  dataValueField: "rego",
  dataSource: data,
  change: function () {                     
    var dataItem = this.dataItem();
    var dataField = options.field.split('.');

     var fieldName = dataField[0];          
     options.model.set(fieldName + '.rego', dataItem.rego);
     options.model.set(fieldName + '.display', dataItem.display);      
    }
 });
 }

我将2个字段设置如下...

I am setting my 2 fields as follows...

    options.model.set(fieldName + '.rego', dataItem.rego);
    options.model.set(fieldName + '.display', dataItem.display);      

(组合中的每个项目,并且网格数据源都有一个带有"rego"和"display"字段的json对象,请参见完整示例

(each item in the combo, and the grid data source has a json object with a 'rego' and 'display' field, see full example here.

这似乎完全符合我的要求,但是我刚刚有人指出,当您使用向上/向下箭头键滚动组合框时,似乎只是在列表中的2个值之间切换,而不是遍历所有项目.如果删除2条"options.model.set"语句,该组合将起作用.

This seemed to work exactly as I wanted, but I had just had someone point out to me that when you scroll the combobox with the up/down arrow keys, it just seems to toggle between 2 values in the list, as opposed to iterating through all the items. If I remove the 2 'options.model.set' statements, the combo then behaves.

我真的希望可以解决此问题,但是我尝试过的一切都没有区别.

I am really hoping there is a work around this, but everything I Have tried makes no different.

如果有任何建议完成此工作,将不胜感激!

If there were any suggestion to finish this off, it would be greatly appreciated!

在此先感谢您的帮助

推荐答案

由于您正在手动修改模型,因此应从输入中删除name=...属性(否则网格也将修改模型;您可以也使用name="car.rego"-它必须是值字段-然后不在配置中设置组合框值),并且仅对模型上的最后一次更改调用set(否则,网格的save事件将得到触发两次,一次触发无效数据.

Since you're modifying the model manually, you should to remove the name=... attribute from the input (otherwise the grid will also modify the model; you could also use name="car.rego" - it has to be the value field - and then not set the combobox value in the config) and also only call set for the last change you make on the model (otherwise, the grid's save event will get triggered twice, once with invalid data).

所以您的编辑器将如下所示:

So you editor would look like this:

function createCombo(container, options, data) {
    var dataField = options.field.split('.');
    var fieldName = dataField[0];

    var input = $('<input/>')
    input.appendTo(container)
    input.kendoComboBox({
        autoBind: true,
        filter: "contains",
        placeholder: "select...",
        suggest: true,
        dataTextField: "display",
        dataValueField: "rego",
        dataSource: data,
        value: options.model[fieldName].rego,
        change: function (e) {
            var dataItem = this.dataItem();
            options.model[fieldName]['rego'] = dataItem.rego;
            options.model.set(fieldName + '.display', dataItem.display);
        }
    });
}

此外,您的数据应保持一致(在一个DS中,您将"C1"用作记录,在另一个"CAR1"中使用).

Also, your data should be consistent (in one DS, you use "C1" as rego, in the other "CAR1").

(演示)

这篇关于Kendo Grid:在组合框选择上设置“模型"字段会中断组合框的向上/向下箭头滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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