My current angular project uses latest angular version with some kendo grids. We have a requirement where I need to have a kendo grid and use kendo multiselects for two of the columns -State, County. So while adding/editing data in the grid, user should be able to select multiple states and the county column should filter the data based on the selected states. I'm not sure how to achieve this.
I've added some basic code as below. State column works fine and lets me pick multiple states. I'm unable to properly filter the County column data based on selected states and bind the data.
My html code:
<kendo-grid style="height:600px" [kendoGridBinding]="statesData">
<kendo-grid-column field="capital" title="Capital City" width="140"></kendo-grid-column>
<kendo-grid-column field="stateName" title="State" width="140" id="stateColumn">
<ng-template kendoGridCellTemplate >
<kendo-multiselect [data]="statesData" textField="stateName" valueField="stateId" (valueChange)="onStateChange($event)">
</kendo-multiselect>
</ng-template>
</kendo-grid-column>
<kendo-grid-column field="countyName" title="County" width="140" id="countyColumn">
<ng-template kendoGridCellTemplate >
<kendo-multiselect [data]="countiesData" textField="countyName" valueField="countyId">
</kendo-multiselect>
</ng-template>
</kendo-grid-column>
</kendo-grid>
TS code:
public statesData: IState[] = states;
public countiesData: ICounty[] = counties;
public onStateChange(values) {
const selStateIds = values.map(s => s.stateId);
const selectedCounties = this.countiesData.filter( c => selStateIds.includes( c.stateId ) );
this.countiesData = selectedCounties;
}
My states data:
export const states: IState[] =
[
{
stateId: 1,
stateName: "Delaware",
capital: "DelCaptital"
},
{
stateId: 2,
stateName: "New York",
capital: "NY Captital"
},
{
stateId: 3,
stateName: "New Jersey",
capital: "NJ Captital"
},
{
stateId: 4,
stateName: "Virginia",
capital: "VA Captital"
},
];
County Data:
export const counties: ICounty[] = [
{
countyId: 1,
stateId: 1,
countyName: "Delaware County 1"
},
{
countyId: 2,
stateId: 1,
countyName: "Delaware County 2"
},
{
countyId: 3,
stateId: 1,
countyName: "Delaware County 3"
},
{
countyId: 4,
stateId: 4,
countyName: "VA County 1"
},
{
countyId: 5,
stateId: 4,
countyName: "VA County 2"
},
{
countyId: 6,
stateId: 4,
countyName: "VA County 3"
},
];
Thank you.
Neelima