Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions apps/demos/Demos/DataGrid/AIAssistant/Vue/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<template>
<DxDataGrid
id="gridContainer"
:dataSource="sales"
:showBorders="true"
keyExpr="Id"
:filterSyncEnabled="true"
>
<DxSearchPanel
:visible="true"
:width="240"
placeholder="Search..."
/>
<DxGroupPanel :visible="true"/>
<DxHeaderFilter :visible="true"/>
<DxFilterRow :visible="true"/>
<DxPaging :pageSize="10"/>
<DxPager
:visible="true"
:allowedPageSizes="[10, 25, 50, 100]"
:showPageSizeSelector="true"
/>

<DxAIAssistant
:enabled="true"
:aiIntegration="aiIntegration"
:chat="chatOptions"
/>

<DxColumn
dataField="Product"
/>
<DxColumn
dataField="Amount"
caption="Sale Amount"
dataType="number"
format="currency"
/>
<DxColumn
dataField="Region"
dataType="string"
/>
<DxColumn
dataField="Sector"
dataType="string"
/>
<DxColumn
dataField="SaleDate"
dataType="date"
/>
<DxColumn
dataField="Customer"
dataType="string"
/>
</DxDataGrid>
</template>

<script setup lang="ts">
import {
DxDataGrid,
DxColumn,
DxSearchPanel,
DxGroupPanel,
DxHeaderFilter,
DxFilterRow,
DxPaging,
DxPager,
DxAIAssistant,
} from 'devextreme-vue/data-grid';
import type dxChat from 'devextreme/ui/chat';
import { type DxChatTypes } from 'devextreme-vue/chat';
import type { DxButtonGroupTypes } from 'devextreme-vue/button-group';
import { sales } from './data.ts';
import { aiIntegration } from './service.ts';

let chatInstance: dxChat | undefined;

const suggestionItems = [
{
text: '💡 Help',
prompt: `💡 The DataGrid AI Assistant allows you to control the component using natural language. You can execute commands such as the following:
• Sort records
• Apply a filter
• Search for a specific value
• Group records by a field
• Focus and select rows
• Modify paging settings
• Pin, resize, and reorder columns
• Configure data summaries
• Pick a suggestion or enter a custom request to get started.`,
},
{
text: '🔍 Filter Sector by Health',
prompt: 'Filter Sector by Health',
},
{
text: '↕️ Sort by Region',
prompt: 'Sort by Region',
},
{
text: '🧩 Group by Product',
prompt: 'Group by Product',
width: 170,
},
];

interface SuggestionItem extends DxButtonGroupTypes.Item {
prompt: string;
}

const onSuggestionItemClick = (e: DxButtonGroupTypes.ItemClickEvent) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const onSuggestionItemClick = (e: DxButtonGroupTypes.ItemClickEvent) => {
const onSuggestionItemClick = (e: DxButtonGroupTypes.ItemClickEvent<SuggestionItem>) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it as is as it writes the ItemClickEvent is not generic

const { prompt, text } = e.itemData as SuggestionItem;
const userId = text === '💡 Help' ? 'help' : 'user';

const message = {
id: Date.now(),
timestamp: new Date(),
author: { id: userId },
text: prompt,
};

chatInstance?.getDataSource().store().push([{
type: 'insert',
data: message,
}]);
};

const chatOptions = {
user: { id: 'user' },
onInitialized(e: DxChatTypes.InitializedEvent) {
chatInstance = e.component;
},
suggestions: {
items: suggestionItems,
onItemClick: onSuggestionItemClick,
},
};
</script>

<style scoped>
#gridContainer {
max-height: 800px;
}
</style>
Loading
Loading