Hi,
Following the steps from How to Cascading DropDownList with Grid editing in Angular Grid component - Syncfusion I wanted to improve the display of DropDownList with Templates in Angular DropDownList component - Syncfusion .
I tried to set the value template directly in ts code and html as ng-template. But neither the one nor the one solution worked. How do I use the valueTemplate in code behind? For now only the declaration for fields are used.
Thanks,
Michael Mairegger
this.customerIdParams = {
create: () => {
this.customerIdElem = document.createElement('input');
return this.customerIdElem;
},
read: () => {
return this.customerIdObj.text;
},
destroy: () => {
this.customerIdObj.destroy();
},
write: (args: { rowData: IInvoiceLine, column: Column }) => {
this.customerIdObj = new DropDownList({
dataSource: this.ordersDataManger,
query: .........,
value: args.rowData.OrderId,
fields: {value: 'Id', text: 'Id'}, valueTemplate: ...HOW TO ASSIGN HERE, change: (changeArgs: ChangeEventArgs) => {
.......
});
this.customerIdObj.appendTo(this.customerIdElem);
}
};
|
this.stateParams = {
create: () => {
this.stateElem = document.createElement('input');
return this.stateElem;
},
read: () => {
return this.stateObj.text;
},
destroy: () => {
this.stateObj.destroy();
},
write: () => {
this.stateObj = new DropDownList({
dataSource: this.state,
fields: { value: 'stateId', text: 'stateName' },
enabled: false,
placeholder: 'Select a state',
floatLabelType: 'Never',
valueTemplate: '<span>${stateId} - ${stateName}</span>',
});
this.stateObj.appendTo(this.stateElem);
},
};
|
Hi Jeseph,
thanks, that solution works.
Now I am in a bit of struggle since I have a complex solution with arrays: I have managed to construct it with the template
${Id} ${DateOfReceipt.getFullYear()} ${RouteLocations[0].TransportDestinationAddress.Country}
But how to display every country. Is calling a local method like this.formatStr() possible. Below you find a sample json
{
"@odata.context": "...",
"value": [
{
"Id": 612,
"DateOfReceipt": "2021-11-23T23:00:00Z",
"RouteLocations": [
{
"TransportDestinationAddress": {
"Country": "IT",
"OtherPropertiesRemoved": "..."
}
},
{
"TransportDestinationAddress": {
"Country": "IT", "OtherPropertiesRemoved": "..."
}
}
]
}
]
}
Regards,
Michael M.
Hi Ajith,
thats correct.
Regards
Michael
|
ngOnInit(): void {
this.stateParams = {
create: () => {
this.stateElem = document.createElement('input');
return this.stateElem;
},
read: () => {
return this.stateObj.text;
},
destroy: () => {
this.stateObj.destroy();
},
write: () => {
this.stateObj = new DropDownList({
dataSource: this.state,
fields: { value: 'stateId', text: 'stateName' },
enabled: false,
placeholder: 'Select a state',
floatLabelType: 'Never',
valueTemplate: '<span>>${customHelp(data)}</span>',
});
this.stateObj.appendTo(this.stateElem);
},
};
(<any>window).customHelp = function(args) {
return args.countryId + ' ' + args.stateId; //here you can format the string by using argument
};
}
|
Hi Rajapandi,
this solution sounds promising. I will verify this after holidays. I will keep you up to date.
Regards,
Michael
Hi Ajith,
the provided solution works. Thank you for the excellent support.
Regards,
Michael