|
4 | 4 | [](https://docs.devexpress.com/GeneralInformation/403183) |
5 | 5 | [](#does-this-example-address-your-development-requirementsobjectives) |
6 | 6 | <!-- default badges end --> |
7 | | -# DevExtreme Examples Template |
| 7 | +# DevExtreme DataGrid - AI Integration |
8 | 8 |
|
9 | | -This is the repository template for creating new examples. |
| 9 | +This example demonstrates how to enhance the [DevExtreme DataGrid](https://js.devexpress.com/Documentation/Guide/UI_Components/DataGrid/Overview/) with two AI-powered features: an [AI column](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/columns/#type) that fills cells with values generated from row context, and the [AI Assistant](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/aiAssistant/) chat that lets end users control the grid (sort, filter, search, group, page, etc.) through natural-language requests. |
10 | 10 |
|
11 | 11 |  |
12 | 12 |
|
13 | | -Use **DevExtreme _Product_ - _Task_** template for a title. |
| 13 | +## Implementation Details |
14 | 14 |
|
15 | | -Describe the solved task in this section. |
| 15 | +### Setup the AI Integration Server |
16 | 16 |
|
17 | | -Put a screenshot/gif that illustrates the result here. |
| 17 | +This example includes a pre-configured ASP.NET Core Web API server (see [AIIntegrationServer](/AIIntegrationServer/)) that acts as a proxy between the client and [Azure OpenAI](https://azure.microsoft.com/en-us/pricing/details/azure-openai/). The server runs at `http://localhost:5005` and exposes the following endpoints: |
| 18 | +- `/api/ai/grid-column` (POST) - Used by the DataGrid AI column to generate cell values. |
| 19 | +- `/api/ai/assistant` (POST) - Used by the AI Assistant to translate chat messages into DataGrid commands. When the request body contains a `responseSchema`, the server forwards it to Azure OpenAI as a structured JSON response format. |
18 | 20 |
|
19 | | -Then, add implementation details (steps, code snippets, and other technical information in a free form), or add a link to an existing document with implementation details. |
| 21 | +Credentials are read from [appsettings.json](AIIntegrationServer/appsettings.json) under the `AzureOpenAI` section (`Endpoint`, `ApiKey`, `ModelName`). The sample is preconfigured to use the public DevExpress demo endpoint; replace those values with your own Azure OpenAI deployment for production use. CORS is enabled for `http://localhost:5050` (the ASP.NET Core front-end) and the framework client dev servers. |
| 22 | + |
| 23 | +### Configure the AIIntegration object |
| 24 | + |
| 25 | +All framework projects share the same client-side pattern: |
| 26 | + |
| 27 | +1. A `sendRequest` factory wraps `fetch` and posts `{ prompt, data }` to the chosen endpoint. The request is aborted via `AbortController` if the user cancels, and oversized prompts (≥ 5000 characters) are rejected before any network call. |
| 28 | + |
| 29 | +2. Two separate [AIIntegration](https://js.devexpress.com/Documentation/ApiReference/Common/Utils/aiIntegration/) instances are created with `new DevExpress.aiIntegration.AIIntegration({ sendRequest })` - one bound to the column endpoint, one to the assistant endpoint. They are passed to the DataGrid via the [aiIntegration](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/#aiIntegration) option and the [aiAssistant.aiIntegration](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/aiAssistant/#aiIntegration) sub-option respectively. |
| 30 | + |
| 31 | +### Configure the DataGrid AI column |
| 32 | + |
| 33 | +A column with `type: 'ai'` enables automatic cell value generation. The [ai](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/columns/ai/) sub-options describe how the model should fill values: |
| 34 | + |
| 35 | +- `prompt` - The natural-language instruction sent to the model with row data as context. |
| 36 | +- `mode` - `'auto'` runs the AI for every visible row automatically; `'manual'` waits for user action. |
| 37 | +- `noDataText` - Placeholder shown while values are being generated. |
| 38 | + |
| 39 | +### Configure the DataGrid AI Assistant |
| 40 | + |
| 41 | +The [aiAssistant](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/aiAssistant/) option turns on a chat panel that issues structured commands to the grid. The embedded [Chat](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxChat/) is configured with: |
| 42 | + |
| 43 | +- `user` - Identifies the end user in the chat data source. |
| 44 | +- `suggestions.items` - Quick-action chips (Help, Filter, Sort, Group). Each item carries a `prompt` payload. |
| 45 | +- `suggestions.onItemClick` - Pushes the suggestion's prompt into the chat data source as a new user (or `help`) message. |
| 46 | +- `onInitialized` - Stores the chat instance reference so suggestions can append messages directly to its data source. |
| 47 | + |
| 48 | +## Run the Example |
| 49 | + |
| 50 | +### Angular, React, Vue, and jQuery |
| 51 | + |
| 52 | +1. **Start the AI Integration Server** |
| 53 | + |
| 54 | + ```bash |
| 55 | + cd AIIntegrationServer |
| 56 | + dotnet run |
| 57 | + ``` |
| 58 | + |
| 59 | + The server starts on `http://localhost:5005`. |
| 60 | + |
| 61 | +2. **Run the Client Application** |
| 62 | + |
| 63 | + - **Angular:** `cd Angular && npm install && npm start` |
| 64 | + - **React:** `cd React && npm install && npm run dev` |
| 65 | + - **Vue:** `cd Vue && npm install && npm run dev` |
| 66 | + - **jQuery:** `cd jQuery && npm install && npm start` |
| 67 | + |
| 68 | +### ASP.NET Core |
| 69 | + |
| 70 | +1. **Start the AI Integration Server** |
| 71 | + |
| 72 | + ```bash |
| 73 | + cd AIIntegrationServer |
| 74 | + dotnet run |
| 75 | + ``` |
| 76 | + |
| 77 | +2. **Run the ASP.NET Core front-end** in a separate terminal: |
| 78 | + |
| 79 | + ```bash |
| 80 | + cd "ASP.NET Core" |
| 81 | + dotnet run |
| 82 | + ``` |
| 83 | + |
| 84 | + The front-end starts on `http://localhost:5050`. |
20 | 85 |
|
21 | 86 | ## Files to Review |
22 | 87 |
|
| 88 | +- *AI Integration Server* |
| 89 | + - [Program.cs](AIIntegrationServer/Program.cs) - App startup, Azure OpenAI client, CORS, and routing |
| 90 | + - [AIIntegrationController.cs](AIIntegrationServer/Controllers/AIIntegrationController.cs) - `/api/ai/grid-column` and `/api/ai/assistant` endpoints |
| 91 | + - [AIIntegrationRequest.cs](AIIntegrationServer/Models/AIIntegrationRequest.cs) - Request/response payload models |
| 92 | + - [AzureOpenAIOptions.cs](AIIntegrationServer/Configuration/AzureOpenAIOptions.cs) - Azure OpenAI configuration binding |
23 | 93 | - **Angular** |
24 | 94 | - [app.component.html](Angular/src/app/app.component.html) |
25 | 95 | - [app.component.ts](Angular/src/app/app.component.ts) |
| 96 | + - [ai.service.ts](Angular/src/app/ai.service.ts) |
26 | 97 | - **React** |
27 | 98 | - [App.tsx](React/src/App.tsx) |
| 99 | + - [service.ts](React/src/service.ts) |
28 | 100 | - **Vue** |
29 | 101 | - [App.vue](Vue/src/App.vue) |
30 | | - - [Home.vue](Vue/src/components/HomeContent.vue) |
| 102 | + - [HomeContent.vue](Vue/src/components/HomeContent.vue) |
| 103 | + - [service.ts](Vue/src/service.ts) |
31 | 104 | - **jQuery** |
32 | 105 | - [index.html](jQuery/src/index.html) |
33 | 106 | - [index.js](jQuery/src/index.js) |
34 | | -- **ASP.NET Core** |
| 107 | +- **ASP.NET Core** |
35 | 108 | - [Index.cshtml](ASP.NET%20Core/Views/Home/Index.cshtml) |
| 109 | + - [grid-ai-service.js](ASP.NET%20Core/wwwroot/js/grid-ai-service.js) |
| 110 | + - [Program.cs](ASP.NET%20Core/Program.cs) |
36 | 111 |
|
37 | 112 | ## Documentation |
38 | 113 |
|
39 | | -- link |
40 | | -- link |
41 | | -- ... |
| 114 | +- [DataGrid - AI-Powered Features Overview](https://js.devexpress.com/Documentation/Guide/UI_Components/DataGrid/AI-Powered_Features/) |
| 115 | +- [DataGrid - AI Column](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/columns/#type) |
| 116 | +- [DataGrid - AI Assistant](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/aiAssistant/) |
| 117 | +- [AIIntegration Utility](https://js.devexpress.com/Documentation/ApiReference/Common/Utils/aiIntegration/) |
42 | 118 |
|
43 | 119 | ## More Examples |
44 | 120 |
|
45 | | -- link |
46 | | -- link |
47 | | -- ... |
| 121 | +- [DevExtreme Chat - AI Integration with Microsoft Agent Framework](https://github.com/DevExpress-Examples/devextreme-chat-ai-integration-ms-agent-framework) |
| 122 | +- [DevExtreme Chat - Integration with OpenAI](https://github.com/DevExpress-Examples/devextreme-chat-openai-integration) |
| 123 | + |
48 | 124 | <!-- feedback --> |
49 | 125 | ## Does This Example Address Your Development Requirements/Objectives? |
50 | 126 |
|
51 | | -[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=devextreme-examples-template&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=devextreme-examples-template&~~~was_helpful=no) |
| 127 | +[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=devextreme-datagrid-ai-integration&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=devextreme-datagrid-ai-integration&~~~was_helpful=no) |
52 | 128 |
|
53 | 129 | (you will be redirected to DevExpress.com to submit your response) |
54 | 130 | <!-- feedback end --> |
0 commit comments