Skip to content

Commit f17819c

Browse files
committed
added DataGrid and TreeList demos for AIColumn
1 parent 1b6249d commit f17819c

File tree

8 files changed

+4360
-0
lines changed

8 files changed

+4360
-0
lines changed

apps/demos/Demos/DataGrid/AIColumn/JQuery/data.js

Lines changed: 1897 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
3+
<head>
4+
<title>DevExtreme Demo</title>
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
8+
<link rel="stylesheet" type="text/css" href="../../../../node_modules/devextreme/dist/css/dx.light.css" />
9+
<script src="../../../../node_modules/jquery/dist/jquery.min.js"></script>
10+
<script src="../../../../node_modules/devextreme-quill/dist/dx-quill.min.js"></script>
11+
<script type="module">
12+
import { AzureOpenAI } from "https://esm.sh/[email protected]";
13+
14+
window.AzureOpenAI = AzureOpenAI;
15+
</script>
16+
<script src="../../../../node_modules/devextreme-dist/js/dx.ai-integration.js"></script>
17+
<link rel="stylesheet" type="text/css" href="../../../../node_modules/devextreme-dist/css/dx.material.blue.light.css" />
18+
<script src="../../../../node_modules/devextreme-dist/js/dx.all.js"></script>
19+
<script src="data.js"></script>
20+
<script src="index.js"></script>
21+
<link rel="stylesheet" type="text/css" href="styles.css" />
22+
</head>
23+
<body class="dx-viewport">
24+
<div class="demo-container">
25+
<div id="gridContainer"></div>
26+
</div>
27+
</body>
28+
</html>
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
$(() => {
2+
3+
const aiService = new AzureOpenAI({
4+
dangerouslyAllowBrowser: true,
5+
deployment,
6+
endpoint,
7+
apiVersion,
8+
apiKey,
9+
});
10+
11+
async function getAIResponse(messages, signal) {
12+
const params = {
13+
messages,
14+
model: deployment,
15+
max_tokens: 1000,
16+
temperature: 0.7,
17+
};
18+
19+
const response = await aiService.chat.completions.create(params, { signal });
20+
const result = response.choices[0].message?.content;
21+
22+
return result;
23+
}
24+
25+
const aiIntegration = new DevExpress.aiIntegration({
26+
sendRequest({ prompt }) {
27+
const controller = new AbortController();
28+
const signal = controller.signal;
29+
30+
const aiPrompt = [
31+
{ role: 'system', content: prompt.system },
32+
{ role: 'user', content: prompt.user },
33+
];
34+
35+
const promise = getAIResponse(aiPrompt, signal);
36+
37+
const result = {
38+
promise,
39+
abort: () => {
40+
controller.abort();
41+
},
42+
};
43+
44+
return result;
45+
},
46+
});
47+
48+
const createTrademarkTemplate = (vehicle) => {
49+
const {
50+
ID,
51+
Name,
52+
TrademarkName,
53+
} = vehicle;
54+
const trademarkWrapper = $('<div>').addClass('trademark__wrapper');
55+
const imgWrapper = $('<div>').addClass('trademark__img-wrapper');
56+
const img = $('<img>').addClass('trademark__img');
57+
img.attr({
58+
src: `../../../../images/vehicles/image_${ID}.png`,
59+
alt: `${TrademarkName} ${Name}`,
60+
});
61+
62+
const popoverId = `popover-${ID}`;
63+
const popoverWrapper = $('<div>');
64+
popoverWrapper.html(`
65+
<div class="license-info__title">License Information</div>
66+
<div class="license-info__content">
67+
<p><strong>Image:</strong> ${TrademarkName} ${Name}</p>
68+
<p><strong>License:</strong> Stock Photo License</p>
69+
<p><strong>Attribution:</strong> © DevExpress Demos</p>
70+
<p><strong>Usage:</strong> For demonstration purposes only</p>
71+
</div>
72+
`);
73+
74+
img.attr('data-popover-target', popoverId);
75+
76+
const popover = $('<div>').attr('id', popoverId).dxPopover({
77+
target: `[data-popover-target="${popoverId}"]`,
78+
showEvent: 'mouseenter',
79+
hideEvent: 'mouseleave',
80+
position: 'top',
81+
contentTemplate: () => popoverWrapper,
82+
});
83+
84+
imgWrapper.append(img, popover);
85+
trademarkWrapper.append(imgWrapper);
86+
87+
const textWrapper = $('<div>').addClass('trademark__text-wrapper');
88+
const trademarkText = $('<div>').addClass('trademark__text trademark__text--title').text(TrademarkName);
89+
const nameText = $('<div>').addClass('trademark__text trademark__text--subtitle').text(Name);
90+
91+
textWrapper.append(trademarkText, nameText);
92+
trademarkWrapper.append(textWrapper);
93+
94+
return trademarkWrapper;
95+
};
96+
97+
const createCategoryTemplate = ({ CategoryName }) => {
98+
return $('<div>').addClass('category__wrapper').text(CategoryName);
99+
}
100+
101+
$('#gridContainer').dxDataGrid({
102+
dataSource: vehicles,
103+
columns: [
104+
{
105+
caption: 'Trademark',
106+
width: 220,
107+
cellTemplate: (container, options) => {
108+
const vehicle = options.data;
109+
const imageWrapper = createTrademarkTemplate(vehicle);
110+
container.append(imageWrapper);
111+
}
112+
},
113+
{
114+
dataField: 'Price',
115+
format: 'currency',
116+
width: 100,
117+
headerFilter: {
118+
groupInterval: 20000,
119+
},
120+
},
121+
{
122+
caption: 'Category',
123+
cellTemplate: (container, options) => {
124+
const category = options.data;
125+
const categoryWrapper = createCategoryTemplate(category);
126+
container.append(categoryWrapper);
127+
}
128+
},
129+
{
130+
dataField: 'Modification',
131+
width: 180
132+
},
133+
{
134+
dataField: 'Horsepower',
135+
width: 140
136+
},
137+
{
138+
dataField: 'BodyStyleName',
139+
caption: 'Body Style',
140+
width: 180
141+
},
142+
{
143+
name: 'AI column',
144+
caption: 'Origin Country',
145+
type: 'ai',
146+
ai: {
147+
aiIntegration,
148+
prompt: 'show the country of origin for the following vehicles',
149+
mode: 'auto',
150+
showHeaderMenu: true,
151+
noDataText: 'No data',
152+
emptyText: 'Unknown',
153+
},
154+
width: 200,
155+
fixed: true,
156+
fixedPosition: "right",
157+
cellTemplate: ($container) => {
158+
$container.addClass("ai__cell");
159+
},
160+
// headerCellTemplate: ($container) => {
161+
// $container.addClass("ai__cell");
162+
// }
163+
}
164+
],
165+
});
166+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.trademark__wrapper {
2+
display: flex;
3+
align-items: center;
4+
gap: 8px;
5+
}
6+
7+
.trademark__img-wrapper {
8+
width: 40px;
9+
height: 40px;
10+
border: 1px solid #E0E0E0;
11+
border-radius: 4px;
12+
cursor: pointer;
13+
transition: border-color 0.2s ease;
14+
}
15+
16+
.trademark__img-wrapper img {
17+
width: 100%;
18+
height: 100%;
19+
object-fit: cover;
20+
object-position: center;
21+
border-radius: 4px;
22+
}
23+
24+
.trademark__text-wrapper {
25+
width: calc(100% - 48px);
26+
}
27+
28+
.trademark__text {
29+
margin: 0;
30+
padding: 0;
31+
}
32+
33+
.trademark__text--title {
34+
font-weight: 600;
35+
}
36+
37+
.trademark__text--subtitle {
38+
font-weight: 400;
39+
}
40+
41+
.category__wrapper {
42+
display: inline-block;
43+
padding: 2px 8px;
44+
background-color: #E0E0E0;
45+
border-radius: 24px;
46+
}
47+
48+
.ai__cell, .dx-command-ai {
49+
background-color: #FAFAFA !important;
50+
}
51+
52+
.license-info__title {
53+
font-size: 14px;
54+
font-weight: 600;
55+
margin-bottom: 8px;
56+
color: #333;
57+
border-bottom: 1px solid #E0E0E0;
58+
padding-bottom: 6px;
59+
}
60+
61+
.license-info__content p {
62+
margin: 4px 0;
63+
font-size: 12px;
64+
line-height: 1.4;
65+
color: #666;
66+
}
67+
68+
.license-info__content strong {
69+
color: #333;
70+
font-weight: 500;
71+
}

0 commit comments

Comments
 (0)