Skip to content

Commit ef60402

Browse files
authored
Migrate Grid Lite samples to v0.4.0 declarative column API with function components (#1028)
1 parent 1a02f37 commit ef60402

31 files changed

Lines changed: 871 additions & 1126 deletions

File tree

browser/package-lock.json

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

browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"dompurify": "^3.3.0",
2525
"file-saver": "1.3.8",
2626
"igniteui-dockmanager": "^1.17.0",
27-
"igniteui-grid-lite": "^0.0.1",
27+
"igniteui-grid-lite": "~0.4.0",
2828
"igniteui-react": "^19.4.0",
2929
"igniteui-react-charts": "19.3.2",
3030
"igniteui-react-core": "19.3.2",

browser/tasks/gulp-samples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ function updateIG(cb) {
861861
// these IG packages are sometimes updated:
862862
{ version: "^6.3.0", name: "igniteui-webcomponents" },
863863
{ version: "^19.4.0", name: "igniteui-react-dockmanager" },
864-
{ version: "^0.0.1", name: "igniteui-grid-lite" },
864+
{ version: "~0.4.0", name: "igniteui-grid-lite" },
865865
// main react packages
866866
{ version: "^19.2.0", name: "react" },
867867
{ version: "^19.2.0", name: "react-dom" },

samples/grids/grid-lite/column-config-basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "eslint ./src/**/*.{ts,tsx}"
1515
},
1616
"dependencies": {
17-
"igniteui-grid-lite": "^0.0.1",
17+
"igniteui-grid-lite": "~0.4.0",
1818
"igniteui-react": "^19.4.0",
1919
"igniteui-webcomponents": "^6.3.0",
2020
"lit-html": "^3.2.0",

samples/grids/grid-lite/column-config-basic/src/index.tsx

Lines changed: 38 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,82 +16,50 @@ import "./index.css";
1616
IgcGridLite.register();
1717
defineComponents(IgcRatingComponent);
1818

19-
export default class Sample extends React.Component<any, any> {
20-
private dataService: GridLiteDataService;
21-
private formatter: Intl.NumberFormat;
22-
private gridRef: React.RefObject<any>;
19+
const formatter = new Intl.NumberFormat('en-EN', {
20+
style: 'currency',
21+
currency: 'EUR'
22+
});
2323

24-
constructor(props: any) {
25-
super(props);
26-
this.dataService = new GridLiteDataService();
27-
this.formatter = new Intl.NumberFormat('en-EN', {
28-
style: 'currency',
29-
currency: 'EUR'
30-
});
31-
this.gridRef = React.createRef();
32-
}
24+
// Define cellTemplate functions outside component
25+
const currencyCellTemplate = (params: any) => {
26+
const span = document.createElement('span');
27+
span.textContent = formatter.format(params.value);
28+
return span;
29+
};
3330

34-
componentDidMount() {
35-
if (this.gridRef.current) {
36-
const data: ProductInfo[] = this.dataService.generateProducts(50);
37-
38-
const columns = [
39-
{
40-
key: 'name',
41-
headerText: 'Product Name'
42-
},
43-
{
44-
key: 'price',
45-
headerText: 'Price',
46-
type: 'number',
47-
cellTemplate: (params: any) => {
48-
const span = document.createElement('span');
49-
span.textContent = this.formatter.format(params.value);
50-
return span;
51-
}
52-
},
53-
{
54-
key: 'sold',
55-
type: 'number',
56-
headerText: 'Units sold'
57-
},
58-
{
59-
key: 'total',
60-
headerText: 'Total sold',
61-
cellTemplate: (params: any) => {
62-
const span = document.createElement('span');
63-
span.textContent = this.formatter.format(params.value);
64-
return span;
65-
}
66-
},
67-
{
68-
key: 'rating',
69-
type: 'number',
70-
headerText: 'Customer rating',
71-
cellTemplate: (params: any) => {
72-
const rating = document.createElement('igc-rating');
73-
rating.setAttribute('readonly', '');
74-
rating.setAttribute('step', '0.01');
75-
rating.setAttribute('value', params.value.toString());
76-
return rating;
77-
}
78-
}
79-
];
31+
const ratingCellTemplate = (params: any) => {
32+
const rating = document.createElement('igc-rating');
33+
rating.setAttribute('readonly', '');
34+
rating.setAttribute('step', '0.01');
35+
rating.setAttribute('value', params.value.toString());
36+
return rating;
37+
};
8038

81-
this.gridRef.current.columns = columns;
82-
this.gridRef.current.data = data;
39+
export default function Sample() {
40+
const gridRef = React.useRef<any>(null);
41+
42+
React.useEffect(() => {
43+
if (gridRef.current) {
44+
const dataService = new GridLiteDataService();
45+
const data: ProductInfo[] = dataService.generateProducts(50);
46+
gridRef.current.data = data;
8347
}
84-
}
48+
}, []);
8549

86-
public render(): JSX.Element {
87-
return (
88-
<div className="container sample ig-typography">
89-
<div className="grid-lite-wrapper">
90-
<igc-grid-lite ref={this.gridRef} id="grid-lite"></igc-grid-lite>
91-
</div>
50+
return (
51+
<div className="container sample ig-typography">
52+
<div className="grid-lite-wrapper">
53+
<igc-grid-lite ref={gridRef} id="grid-lite">
54+
<igc-grid-lite-column field="name" header="Product Name"></igc-grid-lite-column>
55+
<igc-grid-lite-column field="price" header="Price" data-type="number" cellTemplate={currencyCellTemplate}></igc-grid-lite-column>
56+
<igc-grid-lite-column field="sold" data-type="number" header="Units sold"></igc-grid-lite-column>
57+
<igc-grid-lite-column field="total" header="Total sold" cellTemplate={currencyCellTemplate}></igc-grid-lite-column>
58+
<igc-grid-lite-column field="rating" data-type="number" header="Customer rating" cellTemplate={ratingCellTemplate}></igc-grid-lite-column>
59+
</igc-grid-lite>
9260
</div>
93-
);
94-
}
61+
</div>
62+
);
9563
}
9664

9765
// rendering above component in the React DOM

samples/grids/grid-lite/column-config-dynamic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "eslint ./src/**/*.{ts,tsx}"
1515
},
1616
"dependencies": {
17-
"igniteui-grid-lite": "^0.0.1",
17+
"igniteui-grid-lite": "~0.4.0",
1818
"igniteui-react": "^19.4.0",
1919
"igniteui-webcomponents": "^6.3.0",
2020
"lit-html": "^3.2.0",

samples/grids/grid-lite/column-config-dynamic/src/index.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
flex: 1;
2424
}
2525

26-
igc-dropdown-item {
27-
padding: 0.5rem 1rem;
28-
}
29-
3026
.grid-lite-wrapper {
3127
width: 100%;
3228
height: 100%;

0 commit comments

Comments
 (0)