-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.tsx
More file actions
78 lines (68 loc) · 2.21 KB
/
index.tsx
File metadata and controls
78 lines (68 loc) · 2.21 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
68
69
70
71
72
73
74
75
76
77
78
import React from "react";
import ReactDOM from "react-dom/client";
import { GridLiteDataService, ProductInfo } from "./GridLiteDataService";
import { IgrRating } from "igniteui-react";
import {
IgrGridLite,
IgrGridLiteColumn,
type IgrCellContext,
} from "igniteui-react/grid-lite";
import "igniteui-webcomponents/themes/light/bootstrap.css";
import "./index.css";
const formatter = new Intl.NumberFormat("en-150", {
style: "currency",
currency: "EUR",
});
const formatCurrency = (value: number) => formatter.format(value);
// Define cellTemplate functions outside component
const currencyCellTemplate = (ctx: IgrCellContext) => (
<span>{formatCurrency(ctx.value)}</span>
);
const ratingCellTemplate = (ctx: IgrCellContext) => (
<IgrRating readOnly max={5} value={ctx.value}></IgrRating>
);
export default function Sample() {
const [data, setData] = React.useState<ProductInfo[]>([]);
React.useEffect(() => {
const dataService = new GridLiteDataService();
const items: ProductInfo[] = dataService.generateProducts(50);
setData(items);
}, []);
return (
<div className="container sample ig-typography">
<div className="grid-lite-wrapper">
<IgrGridLite data={data} id="grid-lite">
<IgrGridLiteColumn
field="name"
header="Product Name"
></IgrGridLiteColumn>
<IgrGridLiteColumn
field="price"
header="Price"
dataType="number"
cellTemplate={currencyCellTemplate}
></IgrGridLiteColumn>
<IgrGridLiteColumn
field="sold"
dataType="number"
header="Units Sold"
></IgrGridLiteColumn>
<IgrGridLiteColumn
field="total"
header="Total sold"
cellTemplate={currencyCellTemplate}
></IgrGridLiteColumn>
<IgrGridLiteColumn
field="rating"
dataType="number"
header="Customer Rating"
cellTemplate={ratingCellTemplate}
></IgrGridLiteColumn>
</IgrGridLite>
</div>
</div>
);
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<Sample />);