我的数据如下:
var customers = [
{
"ID": 1,
"Name":"John Mayor"
"Company": [{"ID": 1, "Name":"Super Mart"},{"ID": 2, "Name":"Big Mart"}]
"CompanyID":1
}, {
"ID": 2,
"Name": "Rick Bard",
"Company": [{"ID": 1, "Name":"Oracle"},{"ID": 2, "Name":"Google"}]
"CompanyID":2
}
];
我想使用AngularJs和DevExtreme在dxDataGrid中表示数据。因此,Company
列将被查找并选择公司的ID以与CompanyID
绑定。
我想实现类似的目标:
$scope.dataGridOptions = {
dataSource: customers,
columns: ["Name",
{
dataField: "CompanyID",
lookup: {
dataSource:customers[rowindex].Company,
valueExpr: 'ID',
displayExpr: 'Name'
},
caption: 'Company'
}]
};
答案 0 :(得分:1)
您可以在列中添加editCellTemplate以实现目标。这样的事情:
int n; // must have a value
int n = 10; // example, here your variable is initialized
定义模板:
$scope.valueChangeAction = function (e) {
this.setValue(e.value);
};
...
columns: [{
dataField: "CompanyID",
editCellTemplate: "lookupEditCell"
}]
答案 1 :(得分:0)
如@Dmitry所述,添加editCellTemplate
可用于表示数据。但可能不需要dx-item-alias
。
[JAVASCRIPT]
$scope.Customers = [{
"Name": "John Mayor",
"CompanyId": 1,
"Company": [{"ID": 1,"Name": "Super Mart"}, {"ID": 2,"Name": "Big Mart"}]
}, {
"Name": "Rick Bard",
"CompanyId": 2,
"Company": [{ "ID": 1, "Name": "Google" }, { "ID": 2, "Name": "Oracle" }]
}];
$scope.dataGridOptions= {
dataSource: $scope.Customers,
editing: {
mode: 'cell',
allowUpdating: true,
},
columns: [{
dataField: "Name",
allowEditing: false
}, {
dataField: 'CompanyId',
allowEditing: true,
showEditorAlways: true,
editCellTemplate: 'lookupCell',
caption:'Company'
}]
}
$scope.getOnValueChangeAction = function(row) {
return function(e) {
row.setValue(e.value);
}
};
[HTML]
<div dx-data-grid="dataGridOptions">
<div data-options="dxTemplate:{ name:'lookupCell' }">
<div dx-select-box="{
dataSource: data.Company,
value: data.CompanyId,
valueExpr: 'ID',
displayExpr: 'Name',
onValueChanged: $parent.getOnValueChangeAction(this)
}">
</div>
</div>
</div>