Kendo Grid with custom popup editor using MultiSelect - can't get selected items in model

久未见 提交于 2019-12-04 05:04:02
OnaBai

For using MultiSelect in Grids there are a couple o questions to consider:

  1. Grid editors only support as type for columns string, boolean, number and date. Since you will want to save an array of ... let's say string you will have to work around this.
  2. Since you are receiving an array of values from the server, you will have to use a template for serializing it to a string in order to display values received from the server.
  3. KendoUI is not able of guessing that you want to use a MultiSelect as input so you have to provide and editor function.

Let's work around all these questions:

To solve the question of array of string the simplest solution is not saying anything to KendoUI about what is receiving.

For the template, I'm going to be using the JavaScript join method to pull all the values together separated by a ", ". Something like:

{ field: "Cities", template: "#= Cities.join(', ') #" }

Finally for the editor, I use:

{ field: "Cities", template: "#= Cities.join(', ') #", editor : citiesEditor }

function citiesEditor(container, options) {
    $("<select multiple='multiple' data-bind='value : Cities'/>").appendTo(container).kendoMultiSelect({
        dataSource: citiesDS
    });
}

Where in my case citiesDS is just an array of string with the name of valid Cities.

var citiesDS = [
    "Boston", "Kirkland", "London", "New York", "Philadelphia", "Redmond", "Seattle", "Tacoma"
];

When you update (save), it will send to the host an array of strings with the cities introduced in Cities field.

Example: here http://jsfiddle.net/OnaBai/Q2w7z/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!