Skip to content

Commit 9431821

Browse files
committed
add filter
1 parent 11ea905 commit 9431821

File tree

5 files changed

+214
-30
lines changed

5 files changed

+214
-30
lines changed

examples/ecommerce-jewellery-store/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ecommerce-jewellery-store/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13+
"@progress/kendo-data-query": "^1.7.0",
1314
"@progress/kendo-drawing": "^1.21.0",
1415
"@progress/kendo-licensing": "^1.3.5",
1516
"@progress/kendo-react-buttons": "^8.5.0",
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import * as React from "react";
2+
import { filterIcon, sortAscIcon } from "@progress/kendo-svg-icons";
3+
import {
4+
MultiSelect,
5+
DropDownList,
6+
DropDownsPopupSettings,
7+
DropDownListChangeEvent,
8+
MultiSelectChangeEvent,
9+
} from "@progress/kendo-react-dropdowns";
10+
import { SvgIcon } from "@progress/kendo-react-common";
11+
import {
12+
FilterDescriptor,
13+
SortDescriptor,
14+
State,
15+
} from "@progress/kendo-data-query";
16+
17+
const chips: string[] = [
18+
"Bracelets",
19+
"Rings",
20+
"Earrings",
21+
"Watches",
22+
"Necklaces",
23+
];
24+
25+
const statuses: string[] = ["Sale", "Recommended", "Must Have"];
26+
const materials: string[] = ["Gold", "Silver"];
27+
28+
const DropDownSettings: DropDownsPopupSettings = {
29+
minWidth: "119px",
30+
};
31+
32+
export const FilterComponent = (props: any) => {
33+
const [categoryValue, setCategoryValue] = React.useState<string[]>(["Category"]);
34+
const [statusValue, setStatusValue] = React.useState<string>("Recommended");
35+
const [materialValue, setMaterialValue] = React.useState<string>("Material");
36+
37+
const onStatusChange = (e: DropDownListChangeEvent) => {
38+
setStatusValue(e.value);
39+
40+
const newSorts: SortDescriptor[] = [
41+
{
42+
field: "status",
43+
dir: "desc",
44+
},
45+
];
46+
47+
const customCompositeFilters: State = {
48+
filter: undefined,
49+
sort: newSorts,
50+
};
51+
52+
props.updateUI(customCompositeFilters);
53+
};
54+
55+
const onMsChange = (e: MultiSelectChangeEvent) => {
56+
setCategoryValue(e.value);
57+
58+
const newFilters = e.value.map((c: any) => ({
59+
field: "category",
60+
operator: "eq",
61+
value: c,
62+
}));
63+
64+
const customCompositeFilters: State = {
65+
filter: {
66+
logic: "or",
67+
filters: newFilters,
68+
},
69+
sort: undefined,
70+
};
71+
72+
props.updateUI(customCompositeFilters);
73+
setMaterialValue("Material");
74+
};
75+
76+
const onMaterialChange = (e: DropDownListChangeEvent) => {
77+
setMaterialValue(e.value);
78+
79+
const newFilter: FilterDescriptor[] = [
80+
{
81+
field: "material",
82+
operator: "eq",
83+
value: e.value,
84+
},
85+
];
86+
87+
const customCompositeFilters: State = {
88+
filter: {
89+
logic: "or",
90+
filters: newFilter,
91+
},
92+
sort: undefined,
93+
};
94+
95+
props.updateUI(customCompositeFilters);
96+
setCategoryValue(["Category"]);
97+
};
98+
99+
return (
100+
<>
101+
<section className="k-d-flex k-justify-content-between k-align-items-center">
102+
<span className="k-d-flex k-align-items-center">
103+
<span className="k-d-flex k-align-items-center k-pr-2">
104+
<SvgIcon icon={filterIcon}></SvgIcon>
105+
Filter:
106+
</span>
107+
<span className="k-pr-2">
108+
<MultiSelect
109+
popupSettings={DropDownSettings}
110+
style={{
111+
minWidth: "119px",
112+
}}
113+
fillMode={"flat"}
114+
data={chips}
115+
value={categoryValue}
116+
onChange={onMsChange}
117+
></MultiSelect>
118+
</span>
119+
<span className="k-pr-2">
120+
<DropDownList
121+
value={materialValue}
122+
data={materials}
123+
onChange={onMaterialChange}
124+
></DropDownList>
125+
</span>
126+
</span>
127+
128+
<span className="k-d-flex k-align-items-center">
129+
<span className="k-d-flex k-align-items-center k-pr-2">
130+
<SvgIcon icon={sortAscIcon}></SvgIcon>
131+
Sort by:
132+
</span>
133+
<span>
134+
<DropDownList
135+
data={statuses}
136+
value={statusValue}
137+
onChange={onStatusChange}
138+
></DropDownList>
139+
</span>
140+
</span>
141+
</section>
142+
</>
143+
);
144+
};

examples/ecommerce-jewellery-store/src/data/listData.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,128 +23,170 @@ type ListDataDescriptor = {
2323
img: string | null;
2424
status: string | null;
2525
title: string;
26+
category: "Bracelets" | "Earrings" | "Rings" | "Watches" | "Necklaces";
27+
material: "Silver" | "Gold";
2628
oldPrice: number | null;
2729
newPrice: number;
2830
};
2931

3032
export const listData: ListDataDescriptor[] = [{
3133
img: diamongWeddingRing,
3234
status: "sale",
33-
title: "Diamong Wedding Ring",
35+
title: "Diamond Wedding Ring",
36+
category: "Rings",
37+
material: "Silver",
3438
oldPrice: 990,
3539
newPrice: 890
3640
}, {
3741
img: silverBraceletCross,
3842
status: "recommended",
43+
category: "Bracelets",
44+
material: "Silver",
3945
title: "Silver Bracelet with Cross",
4046
oldPrice: null,
4147
newPrice: 270
4248
},
4349
{
4450
img: pinkSilverBracelet,
4551
status: null,
52+
category: "Bracelets",
53+
material: "Silver",
4654
title: "Pink Silver Bracelet",
4755
oldPrice: null,
4856
newPrice: 460
4957
}, {
5058
img: yellowGoldEarrings,
5159
status: "sale",
60+
category: "Earrings",
61+
material: "Silver",
5262
title: "Yellow Gold Earrings",
5363
oldPrice: 500,
5464
newPrice: 380
5565
}, {
5666
img: silverHeartNecklace,
5767
status: null,
68+
category: "Necklaces",
69+
material: "Silver",
5870
title: "Silver Heart Necklace",
5971
oldPrice: null,
6072
newPrice: 400
6173
}, {
6274
img: homemadeSilverEarrings,
6375
status: null,
76+
category: "Earrings",
77+
material: "Silver",
6478
title: "Handmade Silver Earrings",
6579
oldPrice: null,
6680
newPrice: 650
6781
}, {
6882
img: diamondWeddingBands,
6983
status: "recommended",
7084
title: "Diamong Wedding Bands",
85+
material: "Gold",
86+
category: "Rings",
7187
oldPrice: null,
7288
newPrice: 4290
7389
}, {
7490
img: casualSilverWatch,
7591
status: null,
7692
title: "Casual Silver Watch",
93+
category: "Watches",
94+
material: "Silver",
7795
oldPrice: null,
7896
newPrice: 390
7997
}, {
8098
img: silverBraceletOnyx,
8199
status: "sale",
82100
title: "Silver Bracelet with Onyx",
101+
material: "Silver",
102+
category: "Bracelets",
83103
oldPrice: 950,
84104
newPrice: 770
85105
}, {
86106
img: weddingBandsPearl,
87107
status: "must have",
88108
title: "Wedding Bands with Pearls",
109+
material: "Gold",
110+
category: "Rings",
89111
oldPrice: null,
90112
newPrice: 900
91113
}, {
92114
img: silverWeddingBands,
93115
status: null,
94116
title: "Silver Wedding Bands",
117+
material: "Silver",
118+
category: "Rings",
95119
oldPrice: null,
96120
newPrice: 250
97121
}, {
98122
img: handmadeYellowGoldRing,
99123
status: null,
124+
category: "Rings",
125+
material: "Silver",
100126
title: "Handmade Yellow Gold Ring",
101127
oldPrice: null,
102128
newPrice: 560
103129
}, {
104130
img: diamondRingSapphire,
105131
status: "must have",
106132
title: "Diamond Ring with Sapphire",
133+
category: "Rings",
134+
material: "Gold",
107135
oldPrice: null,
108136
newPrice: 3590
109137
}, {
110138
img: silverHeartBracelet,
111139
status: null,
112140
title: "Silver Heart Bracelet",
141+
category: "Bracelets",
142+
material: "Silver",
113143
oldPrice: null,
114144
newPrice: 430
115145
}, {
116146
img: roseGoldEarringsOpal,
117147
status: "Sale",
118148
title: "Rose Gold Earrings with Opal",
149+
category: "Earrings",
150+
material: "Gold",
119151
oldPrice: 850,
120152
newPrice: 690
121153
},{
122154
img: silverBraceletTopaz,
123155
status: null,
156+
category: "Bracelets",
157+
material: "Silver",
124158
title: "Silver Bracelet with Topaz",
125159
oldPrice: null,
126160
newPrice: 580
127161
},{
128162
img: handmadeDiamongRing,
129163
status: null,
164+
category: "Rings",
165+
material: "Gold",
130166
title: "Handmade Diamond Ring",
131167
oldPrice: null,
132168
newPrice: 1100
133169
},{
134170
img: diamondRingRuby,
135171
status: "must have",
172+
category: "Rings",
173+
material: "Gold",
136174
title: "Diamong Ring with Ruby",
137175
oldPrice: null,
138176
newPrice: 5560
139177
},{
140178
img: stainlessSteelWatch,
141179
status: null,
142-
title: "Stainless Steel Watch",
180+
material: "Silver",
181+
category: "Watches",
182+
title: "Silver Watch",
143183
oldPrice: null,
144184
newPrice: 270
145185
}, {
146186
img: goldEarringsGarnet,
147187
status: null,
188+
category: "Earrings",
189+
material: "Gold",
148190
title: "Gold Earrings with Garnet",
149191
oldPrice: null,
150192
newPrice: 270

0 commit comments

Comments
 (0)