Kendo Grid: how to get the selected item from a Combobox cell template when using with Angular

前端 未结 2 421
感情败类
感情败类 2021-01-24 13:11

I have a Kendo grid which I am using within Angular, and have a field with a combo box, that has the editor set to the following function...

 function comboCellT         


        
相关标签:
2条回答
  • 2021-01-24 13:29

    I think you can simply add a change handler to the editor and set it from there:

    function comboCellTemplate(container, options) {
        var input = $('<input name="' + options.field + '" />')
        input.appendTo(container)
        var combobox = input.kendoComboBox({
            autoBind: true,
            filter: "contains",
            placeholder: "select...",
            suggest: true,
            dataTextField: "description",
            dataValueField: "code",
            dataSource: data,
            change: function () {
                options.model.set(options.field, this.dataItem());
            }
        });
    }
    
    0 讨论(0)
  • 2021-01-24 13:45

    Ok, I think I have got to the bottom of this (after lots of diving through the doco)

    I could get everything to work after I discovered that you can give a column a "magical" compare function.

    So using this, my field can go back to binding to the whole json object .. and add the sortable as follows...

    {
      field: "Category",
      title: "Category",
      editor: comboCellTemplate,
      template: "#=Category.description#",
      sortable:{
            compare: function (a, b){
              return a.Category.description.localeCompare(b.Category.description);
            }
    

    },

    Now everything works exactly as I expect, and I don't need to do anything extra in the combobox. I hope this ("simple when you know how") tip can save someone else all the time it took me to find it.

    0 讨论(0)
提交回复
热议问题