当我添加或编辑记录
时,我想在弹出窗口中随机播放字段在下面的小提琴示例中,网格视图列的顺序如First Name,LastName,Cities但是当我在弹出窗口中首先添加或编辑时,我希望字段序列类似于Cities,LastName,FistName。
<div id="grid"></div>
var firstNames = ["Nancy", "Andrew", "Janet", "Margaret", "Steven", "Michael", "Robert", "Laura", "Anne", "Nige"];
var lastNames = ["Davolio", "Fuller", "Leverling", "Peacock", "Buchanan", "Suyama", "King", "Callahan", "Dodsworth",
"White"];
var cities = ["Seattle", "Tacoma", "Kirkland", "Redmond", "London", "Philadelphia", "New York",
"Seattle", "London", "Boston"];
function createRandomData(count) {
var data = [],
now = new Date();
for (var i = 0; i < count; i++) {
var firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
var lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
var city = [];
for (var j = 0; j < Math.floor(Math.random() * 3 + 1); j++) {
city.push(cities[Math.floor(Math.random() * cities.length)]);
}
data.push({
Id: i + 1,
FirstName: firstName,
LastName: lastName,
Cities: city
});
}
return data;
}
function citiesEditor(container, options) {
$("<select multiple='multiple' " +
"data-bind='value : Cities'/>").appendTo(container).kendoMultiSelect({
dataSource: cities
});
}
var ds = new kendo.data.DataSource({
transport: {
read: function (op) {
op.success(createRandomData(300));
},
update: function (op) {
alert("update: " + JSON.stringify(op, null, 2));
op.success(op.data);
}
},
pageSize: 10,
schema: {
model: {
id: "Id",
fields: {
Id: {
type: 'number'
},
FirstName: {
type: 'string'
},
LastName: {
type: 'string'
}
}
}
}
});
var grid = $("#grid").kendoGrid({
dataSource: ds,
editable: "popup",
pageable: {
refresh: true,
pageSizes: true
},
columns: [{
command: "edit",
width: 100
}, {
field: "FirstName",
width: 100,
title: "First Name"
}, {
field: "LastName",
width: 100,
title: "Last Name"
}, {
field: "Cities",
width: 300,
editor: citiesEditor,
template: "#= Cities.join(', ') #"
}]
}).data("kendoGrid");
如何在添加和编辑弹出窗口中随机播放字段。