|
1 | 1 | <script setup lang="ts"> |
2 | | -import { computed, ref } from 'vue'; |
| 2 | +import { ref } from 'vue'; |
3 | 3 |
|
4 | | -import 'devextreme/dist/css/dx.material.blue.light.compact.css'; |
5 | | -import DxButton from 'devextreme-vue/button'; |
| 4 | +import 'devextreme/dist/css/dx.fluent.blue.light.css'; |
| 5 | +import DxDataGrid, { |
| 6 | + DxAI, |
| 7 | + DxAIAssistant, |
| 8 | + DxColumn, |
| 9 | + DxFilterRow, |
| 10 | + DxGroupPanel, |
| 11 | + DxHeaderFilter, |
| 12 | + DxPager, |
| 13 | + DxPaging, |
| 14 | + DxSearchPanel, |
| 15 | +} from 'devextreme-vue/data-grid'; |
| 16 | +import type dxChat from 'devextreme/ui/chat'; |
| 17 | +import type { DxChatTypes } from 'devextreme-vue/chat'; |
| 18 | +import type { DxButtonGroupTypes } from 'devextreme-vue/button-group'; |
6 | 19 |
|
7 | | -const props = defineProps({ |
8 | | - text: { |
9 | | - type: String, |
10 | | - default: 'count', |
| 20 | +import AIService from '../service'; |
| 21 | +import { AI_ASSISTANT_URL, AI_COLUMN_URL, sales } from '../data'; |
| 22 | +
|
| 23 | +const HELP_PROMPT = `💡 The DataGrid AI Assistant allows you to control the component using natural language. You can execute commands such as the following: |
| 24 | + • Sort records |
| 25 | + • Apply a filter |
| 26 | + • Search for a specific value |
| 27 | + • Group records by a field |
| 28 | + • Focus and select rows |
| 29 | + • Modify paging settings |
| 30 | + • Pin, resize, and reorder columns |
| 31 | + • Configure data summaries |
| 32 | + • Pick a suggestion or enter a custom request to get started.`; |
| 33 | +
|
| 34 | +const allowedPageSizes = [10, 25, 50, 100]; |
| 35 | +
|
| 36 | +const service = new AIService(AI_COLUMN_URL, AI_ASSISTANT_URL); |
| 37 | +const chatRef = ref<dxChat | null>(null); |
| 38 | +
|
| 39 | +const chatOptions = { |
| 40 | + onInitialized: (e: DxChatTypes.InitializedEvent) => { |
| 41 | + chatRef.value = e.component ?? null; |
11 | 42 | }, |
12 | | -}); |
13 | | -const count = ref(0); |
14 | | -const buttonText = computed < string > ( |
15 | | - () => `Click ${props.text}: ${count.value}` |
16 | | -); |
17 | | -function clickHandler() { |
18 | | - count.value += 1; |
19 | | -} |
| 43 | + user: { id: 'user' }, |
| 44 | + suggestions: { |
| 45 | + items: [ |
| 46 | + { text: '💡 Help', prompt: HELP_PROMPT }, |
| 47 | + { text: '🔍 Filter Sector by Health', prompt: 'Filter Sector by Health' }, |
| 48 | + { text: '↕️ Sort by Region', prompt: 'Sort by Region' }, |
| 49 | + { text: '🧩 Group by Product', prompt: 'Group by Product', width: 170 }, |
| 50 | + ], |
| 51 | + onItemClick: (e: DxButtonGroupTypes.ItemClickEvent) => { |
| 52 | + const { prompt, text } = e.itemData; |
| 53 | + const userId = text === '💡 Help' ? 'help' : 'user'; |
| 54 | +
|
| 55 | + const message = { |
| 56 | + id: Date.now(), |
| 57 | + timestamp: new Date(), |
| 58 | + author: { id: userId }, |
| 59 | + text: prompt, |
| 60 | + }; |
| 61 | +
|
| 62 | + chatRef.value |
| 63 | + ?.getDataSource() |
| 64 | + .store() |
| 65 | + .push([ |
| 66 | + { |
| 67 | + type: 'insert', |
| 68 | + data: message, |
| 69 | + }, |
| 70 | + ]); |
| 71 | + }, |
| 72 | + }, |
| 73 | +}; |
20 | 74 | </script> |
| 75 | + |
21 | 76 | <template> |
22 | | - <div> |
23 | | - <DxButton |
24 | | - :text="buttonText" |
25 | | - @click="clickHandler" |
26 | | - /> |
| 77 | + <div class="demo-container"> |
| 78 | + <DxDataGrid |
| 79 | + id="grid-container" |
| 80 | + :data-source="sales" |
| 81 | + :ai-integration="service.columnAiIntegration" |
| 82 | + :show-borders="true" |
| 83 | + key-expr="Id" |
| 84 | + :filter-sync-enabled="true" |
| 85 | + > |
| 86 | + <DxSearchPanel |
| 87 | + :visible="true" |
| 88 | + :width="240" |
| 89 | + placeholder="Search..." |
| 90 | + /> |
| 91 | + <DxGroupPanel :visible="true"/> |
| 92 | + <DxHeaderFilter :visible="true"/> |
| 93 | + <DxFilterRow :visible="true"/> |
| 94 | + <DxPaging :page-size="10"/> |
| 95 | + <DxPager |
| 96 | + :visible="true" |
| 97 | + :allowed-page-sizes="allowedPageSizes" |
| 98 | + :show-page-size-selector="true" |
| 99 | + /> |
| 100 | + |
| 101 | + <DxAIAssistant |
| 102 | + :enabled="true" |
| 103 | + :ai-integration="service.assistantAiIntegration" |
| 104 | + :chat="chatOptions" |
| 105 | + /> |
| 106 | + |
| 107 | + <DxColumn data-field="Product"/> |
| 108 | + <DxColumn |
| 109 | + data-field="Amount" |
| 110 | + caption="Sale Amount" |
| 111 | + data-type="number" |
| 112 | + format="currency" |
| 113 | + /> |
| 114 | + <DxColumn |
| 115 | + data-field="Region" |
| 116 | + data-type="string" |
| 117 | + /> |
| 118 | + <DxColumn |
| 119 | + data-field="Sector" |
| 120 | + data-type="string" |
| 121 | + /> |
| 122 | + <DxColumn |
| 123 | + data-field="SaleDate" |
| 124 | + data-type="date" |
| 125 | + /> |
| 126 | + <DxColumn |
| 127 | + data-field="Customer" |
| 128 | + data-type="string" |
| 129 | + /> |
| 130 | + <DxColumn |
| 131 | + name="AI column" |
| 132 | + caption="AI Column" |
| 133 | + type="ai" |
| 134 | + :width="200" |
| 135 | + :fixed="true" |
| 136 | + fixed-position="right" |
| 137 | + css-class="ai-cell" |
| 138 | + > |
| 139 | + <DxAI |
| 140 | + :prompt="` |
| 141 | + Identify the country where product is manufactured. |
| 142 | + When looking up a country, consider Sector and Customers. |
| 143 | + `" |
| 144 | + mode="auto" |
| 145 | + no-data-text="No data" |
| 146 | + /> |
| 147 | + </DxColumn> |
| 148 | + </DxDataGrid> |
27 | 149 | </div> |
28 | 150 | </template> |
| 151 | + |
| 152 | +<style> |
| 153 | +.demo-container { |
| 154 | + display: flex; |
| 155 | + justify-content: center; |
| 156 | + margin: 20px; |
| 157 | +} |
| 158 | +
|
| 159 | +#grid-container { |
| 160 | + max-width: 1200px; |
| 161 | + width: 100%; |
| 162 | +} |
| 163 | +
|
| 164 | +#grid-container .ai-cell { |
| 165 | + background-color: var(--dx-datagrid-row-alternation-bg); |
| 166 | +} |
| 167 | +</style> |
0 commit comments