juk
juk

Reputation: 2329

kendoGrid: combobox field from json data

Here's field:

{ field: "category", title: "Category", width: 100, editor: categoryDropDownEditor },

custom editor:

function categoryDropDownEditor(container, options) {
  console.log('used editor')
  $('<input data-text-field="category" data-value-field="category" data-bind="value:'+options.field+'"/>')
    .appendTo(container)
    .kendoDropDownList({
      autoBind: false,
      dataSource: {
        type: "json",
        transport: {
          read: "/api/notes/dumpcats"
        }
      }
    })
}

also in model.fields:

  category: {
    type: "combobox",
    editable: true,
    validation: { required: true }
  },

No errors, just empty combobox along with input box which errors when category typed in.

Uncaught TypeError: Property '_parse' of object [object Object] is not a function

i used example here

Upvotes: 2

Views: 1890

Answers (1)

juk
juk

Reputation: 2329

Issue was fixed, as Burke Holland pointed out posting answer below:

  function categoryDropDownEditor(contrainer, options) {
    $('<input data-text-field="category" data-value-field="category" data-bind="value:' + options.field + '"/>"')
      .appendTo(contrainer)
      .kendoComboBox({
        index: 0,
        placeholder: "Select category",
        dataTextField: "category",
        dataValueField: "category",
        dataSource: {
          transport: {
            read: {
              url: '/api/notes/cats',
              dataType: 'json',
              type: 'GET',
            },
          },
          schema: {
            data: function(reply) {
              return reply.rows
            },
          }
        }
      })
  }

Upvotes: 2

Related Questions