Reputation: 1
https://github.com/akveo/ng2-smart-table In settings object,we define structure to show fields like name, title etc.I want to assign object to columns directly. Object contains fields
only.settings = {
editable: false,
mode: 'inline',
add: {
confirmCreate: true
},
edit: {
confirmSave: true,
},
actions: {
delete: false
},
columns: {
food: {
title: 'Food',
filter: false,
},
quantity: {
title: 'Quantity',
filter: false,
},
unit: {
title: 'Unit',
filter: false,
editor: {
type: 'list',
config: {
list: [
{ value: 'gm', title: 'gm' },
{ value: 'slice', title: 'slice' },
{ value: 'cup', title: 'cup' },
{ value: 'glass', title: 'glass' },
{ value: 'pcs', title: 'pcs' },
{ value: 'ml', title: 'ml' },
{ value: 'bowl', title: 'bowl' },
{ value: 'tbspn', title: 'tbspn' }
]
}
}
},
I have to create
array =>units[]= { value: 'bowl', title: 'bowl' },{ value: 'tbspn', title: 'tbspn' }
Want to Assign =>
list: this.units
but its not working. It's in case when I get array by web service call.
Upvotes: 0
Views: 4197
Reputation: 66
Code:
const options = [];
for (const unit of units) {
options.push({ value: unit.val, title: unit.name });
}
this.settings.columns.unit.editor.config.list = options;
this.settings = Object.assign({}, this.settings);
Upvotes: 2
Reputation: 1920
After you receive your array from the webservice, map the elements to convert to the structure used in smart-table.
For map reference: Array.map
It would be something like:
config.list = unitsFromWebservice.map(function(unit) {
return { value: unit, title: unit };
});
Upvotes: 0