Skip to content

Commit 06dc148

Browse files
Merge pull request #3 from DevExpress-Examples/react
React
2 parents b251635 + 8643507 commit 06dc148

8 files changed

Lines changed: 17098 additions & 32 deletions

File tree

React/package-lock.json

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

React/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "vite",
7+
"dev": "vite --port 5050",
88
"prebuild": "devextreme-license --out src/devextreme-license.ts --force",
99
"build": "tsc -b && vite build",
1010
"test": "vitest",
@@ -15,8 +15,8 @@
1515
"preview": "vite preview"
1616
},
1717
"dependencies": {
18-
"devextreme": "26.1.2-beta",
19-
"devextreme-react": "26.1.2-beta",
18+
"devextreme": "26.1.3",
19+
"devextreme-react": "26.1.3",
2020
"react": "^18.2.0",
2121
"react-dom": "^18.2.0"
2222
},

React/src/App.css

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
.main {
2-
margin: 50px;
3-
width: 90vw;
1+
.demo-container {
2+
display: flex;
3+
justify-content: center;
4+
margin: 20px;
5+
}
6+
7+
#grid-container {
8+
max-width: 1200px;
9+
width: 100%;
10+
}
11+
12+
#grid-container .ai-cell {
13+
background-color: var(--dx-datagrid-row-alternation-bg);
414
}

React/src/App.tsx

Lines changed: 115 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,122 @@
1-
import { useCallback, useState } from 'react';
1+
import { useMemo, useRef } from 'react';
2+
import DataGrid, {
3+
AI,
4+
AIAssistant,
5+
Column,
6+
FilterRow,
7+
GroupPanel,
8+
HeaderFilter,
9+
Pager,
10+
Paging,
11+
SearchPanel,
12+
} from 'devextreme-react/data-grid';
13+
import type { ButtonGroupTypes } from 'devextreme-react/button-group';
14+
import type { ChatTypes } from 'devextreme-react/chat';
15+
import type dxChat from 'devextreme/ui/chat';
16+
import 'devextreme/dist/css/dx.fluent.blue.light.css';
217
import './App.css';
3-
import 'devextreme/dist/css/dx.material.blue.light.compact.css';
4-
import Button from 'devextreme-react/button';
18+
19+
import AIService from './service';
20+
import { AI_ASSISTANT_URL, AI_COLUMN_URL, sales } from './data';
21+
22+
const HELP_PROMPT = `💡 The DataGrid AI Assistant allows you to control the component using natural language. You can execute commands such as the following:
23+
• Sort records
24+
• Apply a filter
25+
• Search for a specific value
26+
• Group records by a field
27+
• Focus and select rows
28+
• Modify paging settings
29+
• Pin, resize, and reorder columns
30+
• Configure data summaries
31+
• Pick a suggestion or enter a custom request to get started.`;
32+
33+
const allowedPageSizes = [10, 25, 50, 100];
34+
35+
const service = new AIService(AI_COLUMN_URL, AI_ASSISTANT_URL);
536

637
function App(): JSX.Element {
7-
var [count, setCount] = useState<number>(0);
8-
const clickHandler = useCallback(() => {
9-
setCount((prev) => prev + 1);
10-
}, [setCount]);
38+
const chatRef = useRef<dxChat | null>(null);
39+
40+
const chatOptions = useMemo(() => ({
41+
onInitialized: (e: ChatTypes.InitializedEvent) => {
42+
chatRef.current = e.component || null;
43+
},
44+
user: { id: 'user' },
45+
suggestions: {
46+
items: [
47+
{ text: '💡 Help', prompt: HELP_PROMPT },
48+
{ text: '🔍 Filter Sector by Health', prompt: 'Filter Sector by Health' },
49+
{ text: '↕️ Sort by Region', prompt: 'Sort by Region' },
50+
{ text: '🧩 Group by Product', prompt: 'Group by Product', width: 170 },
51+
],
52+
onItemClick: (e: ButtonGroupTypes.ItemClickEvent) => {
53+
const { prompt, text } = e.itemData;
54+
const userId = text === '💡 Help' ? 'help' : 'user';
55+
56+
const message = {
57+
id: Date.now(),
58+
timestamp: new Date(),
59+
author: { id: userId },
60+
text: prompt,
61+
};
62+
63+
chatRef.current?.getDataSource().store().push([{
64+
type: 'insert',
65+
data: message,
66+
}]);
67+
},
68+
},
69+
}), []);
70+
1171
return (
12-
<div className="main">
13-
<Button text={`Click count: ${count}`} onClick={clickHandler} />
72+
<div className="demo-container">
73+
<DataGrid
74+
id="grid-container"
75+
dataSource={sales}
76+
aiIntegration={service.columnAiIntegration}
77+
showBorders
78+
keyExpr="Id"
79+
filterSyncEnabled
80+
>
81+
<SearchPanel visible width={240} placeholder="Search..." />
82+
<GroupPanel visible />
83+
<HeaderFilter visible />
84+
<FilterRow visible />
85+
<Paging defaultPageSize={10} />
86+
<Pager
87+
visible
88+
allowedPageSizes={allowedPageSizes}
89+
showPageSizeSelector
90+
/>
91+
92+
<AIAssistant
93+
enabled
94+
aiIntegration={service.assistantAiIntegration}
95+
chat={chatOptions}
96+
/>
97+
98+
<Column dataField="Product" />
99+
<Column dataField="Amount" caption="Sale Amount" dataType="number" format="currency" />
100+
<Column dataField="Region" dataType="string" />
101+
<Column dataField="Sector" dataType="string" />
102+
<Column dataField="SaleDate" dataType="date" />
103+
<Column dataField="Customer" dataType="string" />
104+
<Column
105+
name="AI column"
106+
caption="AI Column"
107+
type="ai"
108+
width={200}
109+
fixed
110+
fixedPosition="right"
111+
cssClass="ai-cell"
112+
>
113+
<AI
114+
prompt="Identify the country where product is manufactured. When looking up a country, consider Sector and Customers."
115+
mode="auto"
116+
noDataText="No data"
117+
/>
118+
</Column>
119+
</DataGrid>
14120
</div>
15121
);
16122
}

0 commit comments

Comments
 (0)