-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.tsx
More file actions
67 lines (57 loc) · 2.26 KB
/
index.tsx
File metadata and controls
67 lines (57 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React from 'react';
import ReactDOM from 'react-dom/client';
import { GridLiteDataService, ProductInfo } from './GridLiteDataService';
// Import the web component
import { IgcGridLite } from 'igniteui-grid-lite';
import {
defineComponents,
IgcRatingComponent
} from 'igniteui-webcomponents';
import "igniteui-webcomponents/themes/light/bootstrap.css";
import "./index.css";
// Register components
IgcGridLite.register();
defineComponents(IgcRatingComponent);
const formatter = new Intl.NumberFormat('en-EN', {
style: 'currency',
currency: 'EUR'
});
// Define cellTemplate functions outside component
const currencyCellTemplate = (params: any) => {
const span = document.createElement('span');
span.textContent = formatter.format(params.value);
return span;
};
const ratingCellTemplate = (params: any) => {
const rating = document.createElement('igc-rating');
rating.setAttribute('readonly', '');
rating.setAttribute('step', '0.01');
rating.setAttribute('value', params.value.toString());
return rating;
};
export default function Sample() {
const gridRef = React.useRef<any>(null);
React.useEffect(() => {
if (gridRef.current) {
const dataService = new GridLiteDataService();
const data: ProductInfo[] = dataService.generateProducts(50);
gridRef.current.data = data;
}
}, []);
return (
<div className="container sample ig-typography">
<div className="grid-lite-wrapper">
<igc-grid-lite ref={gridRef} id="grid-lite">
<igc-grid-lite-column field="name" header="Product Name"></igc-grid-lite-column>
<igc-grid-lite-column field="price" header="Price" data-type="number" cellTemplate={currencyCellTemplate}></igc-grid-lite-column>
<igc-grid-lite-column field="sold" data-type="number" header="Units sold"></igc-grid-lite-column>
<igc-grid-lite-column field="total" header="Total sold" cellTemplate={currencyCellTemplate}></igc-grid-lite-column>
<igc-grid-lite-column field="rating" data-type="number" header="Customer rating" cellTemplate={ratingCellTemplate}></igc-grid-lite-column>
</igc-grid-lite>
</div>
</div>
);
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);