Skip to content

Commit dce4abf

Browse files
authored
AI Assistant: DataGrid - write JS frameworks demos (Vue) (#33668)
Co-authored-by: Raushen
1 parent f0b0755 commit dce4abf

5 files changed

Lines changed: 17186 additions & 0 deletions

File tree

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<template>
2+
<DxDataGrid
3+
id="gridContainer"
4+
:dataSource="sales"
5+
:showBorders="true"
6+
keyExpr="Id"
7+
:filterSyncEnabled="true"
8+
>
9+
<DxSearchPanel
10+
:visible="true"
11+
:width="240"
12+
placeholder="Search..."
13+
/>
14+
<DxGroupPanel :visible="true"/>
15+
<DxHeaderFilter :visible="true"/>
16+
<DxFilterRow :visible="true"/>
17+
<DxPaging :pageSize="10"/>
18+
<DxPager
19+
:visible="true"
20+
:allowedPageSizes="[10, 25, 50, 100]"
21+
:showPageSizeSelector="true"
22+
/>
23+
24+
<DxAIAssistant
25+
:enabled="true"
26+
:aiIntegration="aiIntegration"
27+
:chat="chatOptions"
28+
/>
29+
30+
<DxColumn
31+
dataField="Product"
32+
/>
33+
<DxColumn
34+
dataField="Amount"
35+
caption="Sale Amount"
36+
dataType="number"
37+
format="currency"
38+
/>
39+
<DxColumn
40+
dataField="Region"
41+
dataType="string"
42+
/>
43+
<DxColumn
44+
dataField="Sector"
45+
dataType="string"
46+
/>
47+
<DxColumn
48+
dataField="SaleDate"
49+
dataType="date"
50+
/>
51+
<DxColumn
52+
dataField="Customer"
53+
dataType="string"
54+
/>
55+
</DxDataGrid>
56+
</template>
57+
58+
<script setup lang="ts">
59+
import {
60+
DxDataGrid,
61+
DxColumn,
62+
DxSearchPanel,
63+
DxGroupPanel,
64+
DxHeaderFilter,
65+
DxFilterRow,
66+
DxPaging,
67+
DxPager,
68+
DxAIAssistant,
69+
} from 'devextreme-vue/data-grid';
70+
import type dxChat from 'devextreme/ui/chat';
71+
import { type DxChatTypes } from 'devextreme-vue/chat';
72+
import type { DxButtonGroupTypes } from 'devextreme-vue/button-group';
73+
import { sales } from './data.ts';
74+
import { aiIntegration } from './service.ts';
75+
76+
let chatInstance: dxChat | undefined;
77+
78+
const suggestionItems = [
79+
{
80+
text: '💡 Help',
81+
prompt: `💡 The DataGrid AI Assistant allows you to control the component using natural language. You can execute commands such as the following:
82+
• Sort records
83+
• Apply a filter
84+
• Search for a specific value
85+
• Group records by a field
86+
• Focus and select rows
87+
• Modify paging settings
88+
• Pin, resize, and reorder columns
89+
• Configure data summaries
90+
• Pick a suggestion or enter a custom request to get started.`,
91+
},
92+
{
93+
text: '🔍 Filter Sector by Health',
94+
prompt: 'Filter Sector by Health',
95+
},
96+
{
97+
text: '↕️ Sort by Region',
98+
prompt: 'Sort by Region',
99+
},
100+
{
101+
text: '🧩 Group by Product',
102+
prompt: 'Group by Product',
103+
width: 170,
104+
},
105+
];
106+
107+
interface SuggestionItem extends DxButtonGroupTypes.Item {
108+
prompt: string;
109+
}
110+
111+
const onSuggestionItemClick = (e: DxButtonGroupTypes.ItemClickEvent) => {
112+
const { prompt, text } = e.itemData as SuggestionItem;
113+
const userId = text === '💡 Help' ? 'help' : 'user';
114+
115+
const message = {
116+
id: Date.now(),
117+
timestamp: new Date(),
118+
author: { id: userId },
119+
text: prompt,
120+
};
121+
122+
chatInstance?.getDataSource().store().push([{
123+
type: 'insert',
124+
data: message,
125+
}]);
126+
};
127+
128+
const chatOptions = {
129+
user: { id: 'user' },
130+
onInitialized(e: DxChatTypes.InitializedEvent) {
131+
chatInstance = e.component;
132+
},
133+
suggestions: {
134+
items: suggestionItems,
135+
onItemClick: onSuggestionItemClick,
136+
},
137+
};
138+
</script>
139+
140+
<style scoped>
141+
#gridContainer {
142+
max-height: 800px;
143+
}
144+
</style>

0 commit comments

Comments
 (0)