本帖最后由 Richard.Ma 于 2019-11-21 11:16 编辑
还是以demo中下面的页面来修改
在CustomGridEditor中生成的wijmo.input.ComboBox中,有一个gotFocus事件,目前通过这个事件来修改数据源,这样子显示出来的时候就是对应的city了
- // create data maps
- var countryMap = new wijmo.grid.DataMap(getCountries(), 'id', 'name');
- //var cityMap = new wijmo.grid.DataMap(getCities(), 'id', 'name');
- var city = getCities();
- var theGrid = wijmo.Control.getControl('#theGrid');
- theGrid.itemsSource = getData();
- theGrid.columns[0].dataMap = countryMap;
- // create an editor based on a ComboBox
- var multiColumnEditor = new CustomGridEditor(theGrid, 'city', wijmo.input.ComboBox, {
- headerPath: 'name',
- displayMemberPath: 'name',
-
- itemsSource: city
- });
- // customize the ComboBox to show multiple columns
- var combo = multiColumnEditor.control;
- combo.listBox.formatItem.addHandler(function (s, e) {
- e.item.innerHTML = '<table><tr>' +
- '<td style="width:30px;text-align:right;padding-right:6px">' + e.data.id + '</td>' +
- '<td style="width:100px;padding-right:6px"><b>' + e.data.name + '</b></td>' +
- '<td style="width:100px;padding-right:6px">' + e.data.country +'</td>' +
- '</tr></table>';
- });
- combo.gotFocus.addHandler(function () {
- combo.itemsSource = getCitiesOfOneCountry();
- });
- function getCitiesOfOneCountry() {
-
- var arr = [];
- cities = getCities(),
- country = theGrid.collectionView.currentItem.country;
- for (var i = 0; i < cities.length; i++) {
- var city = cities[i];
- if (city.country == country) {
- arr.push(city);
- }
- }
- return arr;
- };
复制代码
|