App.component.html
<ejs-grid #grid [dataSource]='data' allowGrouping="true" allowFiltering="true" [editSettings]='editSettings' [toolbar]='toolbar' allowPaging="true" allowSorting="true" height="320">
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' isPrimaryKey='true' width=100></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
<e-column field='ShipCountry' headerText='Ship Country' editType='dropdownedit'
[edit]='countryParams' width=150></e-column>
<e-column field='ShipCity' headerText='Ship State' editType='dropdownedit' [edit]='stateParams' width=150></e-column>
</e-columns>
</ejs-grid>
App.component.ts
export class FetchDataComponent {
---------
ngOnInit(): void {
--------
this.countryParams = {
create: () => {
this.countryElem = document.createElement('input');
return this.countryElem;
},
read: () => {
return this.countryObj.text;
},
destroy: () => {
this.countryObj.destroy();
},
write: () => {
this.countryObj = new DropDownList({
dataSource: new DataManager(this.country),
fields: { value: 'countryId', text: 'countryName' },
change: () => {
const commQuery: Query = new Query();
new DataManager({ url: "/Home/UrlDatasource", adaptor: new UrlAdaptor })
.executeQuery(commQuery)
.then((a:any) => {
// change the datasource of the dropwon element
this.stateObj.dataSource = new DataManager (DataUtil.distinct(a.result, "ShipCity", true)),
this.stateObj.query = commQuery;
this.stateObj.enabled = true;
this.stateObj.dataBind();
});
},
placeholder: 'Select a country',
floatLabelType: 'Never'
});
this.countryObj.appendTo(this.countryElem);
}
};
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: new DataManager(this.state),
fields: { value: 'ShipCity', text: 'ShipCity' },
enabled: false,
placeholder: 'Select a state',
floatLabelType: 'Never'
});
this.stateObj.appendTo(this.stateElem);
}
};
}
}
|