簡體   English   中英

Kendo Grid:與Angular一起使用時,如何從組合框單元格模板中獲取所選項目

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

我有一個在Angular中使用的Kendo網格,並且有一個帶有組合框的字段,其編輯器設置為以下功能...

 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,
  });

數據是簡單的json對象的列表...

[
  {code: 'code1', description: 'desc1'}
  {code: 'code2', description: 'desc2'}
[

網格數據中的每個字段都綁定到相同的對象(即帶有代碼和描述字段)

在上一篇文章中,要進行排序和過濾,我需要將一個字段綁定到顯示字段...

 {
      field: "Category.description",
      title: "Category",
      editor: comboCellTemplate,
      template: "#=Category.description#"
  },

當我這樣做時,組合框似乎將網格的字段設置為代碼。 我如何才能將網格數據設置為整個數據對象(即{code,description})

我試圖添加一個on-change handler來做到這一點

  input.on('change', function () {
    var val = input.val();              
            //var dataItem = input.dataItem();
    options.model.set(options.field, val + 'xx');
  });

但看不到如何從組合中獲取“選定項”

我似乎無法在幫助中找到它(特別是在使用Angular時)

在這里的任何幫助將不勝感激。 問候,彼得

我認為您只需將更改處理程序添加到編輯器中,然后從那里進行設置:

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());
        }
    });
}

好吧,我想我已經深入到此(經過大量潛水經歷)

當我發現您可以為列賦予“神奇”的比較功能后,我便可以進行所有工作。

因此,使用此字段,我的字段可以返回綁定到整個json對象..並按如下所示添加sortable ...

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

},

現在,一切都按我的預期工作,並且不需要在組合框中執行任何其他操作。 我希望這個技巧(“簡單易懂”)可以在我花了很多時間才為別人省掉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM