Skip to content

Commit 2f6cc1d

Browse files
authored
Update cascading combos topic for React 19 (#1505)
1 parent aee18be commit 2f6cc1d

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

doc/en/components/grids/_shared/cascading-combos.md

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ builder.Services.AddIgniteUIBlazor(
5050
```
5151

5252
```tsx
53-
import { IgrComboModule, IgrCombo } from 'igniteui-react';
54-
IgrComboModule.register();
53+
import { IgrCombo } from 'igniteui-react';
5554
```
5655

5756
Then you should define the column template with the combo:
@@ -61,22 +60,28 @@ Then you should define the column template with the combo:
6160
<IgrColumn
6261
field="Country"
6362
header="Country"
64-
bodyTemplate={webGridCountryDropDownTemplate}
65-
name="column1">
63+
bodyTemplate={webGridCountryDropDownTemplate}>
6664
</IgrColumn>
6765
```
6866

6967
```tsx
70-
function webGridCountryDropDownTemplate(props: {dataContext: IgrCellTemplateContext}) => {
71-
var cell = props.dataContext.cell as any;
72-
if (cell === undefined) {
73-
return <></>;
74-
}
75-
const id = cell.id.rowID;
76-
const comboId = "country" + id;
68+
const webGridCountryDropDownTemplate = (ctx: IgrCellTemplateContext) => {
69+
const rowId = ctx.cell?.id.rowID;
70+
if (!rowId) return <></>;
71+
const comboId = `country_${rowId}`;
72+
7773
return (
7874
<>
79-
<IgrCombo data={countries} ref={comboRefs} change={(x: any, args: any) => {onCountryChange(id, x, args) }} placeholder="Choose Country..." valueKey="Country" displayKey="Country" singleSelect="true" name={comboId}></IgrCombo>
75+
<IgrCombo
76+
data={countries}
77+
ref={getComboRef(comboId)}
78+
onChange={(event: CustomEvent) => { onCountryChange(rowId, event) }}
79+
placeholder="Choose Country..."
80+
valueKey="Country"
81+
displayKey="Country"
82+
singleSelect={true}
83+
name={comboId}>
84+
</IgrCombo>
8085
</>
8186
);
8287
}
@@ -105,7 +110,7 @@ public webGridCountryDropDownTemplate: IgcRenderFunction<IgcCellTemplateContext>
105110

106111
- `displayKey` - Required for object arrays - Specifies which property will be used for the items' text. If no value is specified for `displayKey`, the combo will use the specified `valueKey` (if any).
107112

108-
In order to handle the selection change, we need the `change` event. The emitted event arguments contain information about the selection prior to the change, the current selection and the items that were added or removed. Therefore, it will filter the values based on the selection of the previous combo.
113+
In order to handle the selection change, we need the `onChange` event. The emitted event arguments contain information about the selection prior to the change, the current selection and the items that were added or removed. Therefore, it will filter the values based on the selection of the previous combo.
109114

110115
```razor
111116
//In Javascript
@@ -163,19 +168,28 @@ public bindEventsCountryCombo(rowId: any, cell: any) {
163168
```
164169

165170
```tsx
166-
function onCountryChange(rowId: string, cmp: any, args:any) {
167-
const regionCombo = comboRefCollection.get("region_" + rowId);
168-
setTimeout(() => {
169-
const newValue = cmp.value[0];
170-
if (newValue === undefined) {
171-
regionCombo.deselect(regionCombo.value);
172-
regionCombo.disabled = true;
173-
regionCombo.data = [];
174-
} else {
175-
regionCombo.disabled = false;
176-
regionCombo.data = regions.filter(x => x.Country === newValue);
177-
}
178-
});
171+
const onCountryChange = (rowId: string, event: CustomEvent) => {
172+
const regionCombo = getComboRef(`region_${rowId}`).current;
173+
const cityCombo = getComboRef(`city_${rowId}`).current;
174+
const regions = regions;
175+
const newValue = event.detail.newValue[0];
176+
177+
if (newValue === undefined) {
178+
regionCombo.deselect(regionCombo.value);
179+
regionCombo.disabled = true;
180+
regionCombo.data = [];
181+
182+
cityCombo.deselect(regionCombo.value);
183+
cityCombo.disabled = true;
184+
cityCombo.data = [];
185+
} else {
186+
regionCombo.disabled = false;
187+
regionCombo.data = regions.filter(x => x.Country === newValue);
188+
189+
cityCombo.deselect(cityCombo.value);
190+
cityCombo.disabled = true;
191+
cityCombo.data = [];
192+
}
179193
}
180194
```
181195

0 commit comments

Comments
 (0)