|
| 1 | +<template> |
| 2 | + <DxTreeList |
| 3 | + id="employees" |
| 4 | + keyExpr="ID" |
| 5 | + parentIdExpr="Head_ID" |
| 6 | + :dataSource="employees" |
| 7 | + :autoExpandAll="true" |
| 8 | + :showBorders="true" |
| 9 | + :aiIntegration="aiIntegration" |
| 10 | + :onAIColumnRequestCreating="onAIColumnRequestCreating" |
| 11 | + > |
| 12 | + <DxScrolling :mode="'standard'"/> |
| 13 | + <DxPaging |
| 14 | + :enabled="true" |
| 15 | + :pageSize="10" |
| 16 | + /> |
| 17 | + <DxColumnFixing :enabled="true"/> |
| 18 | + |
| 19 | + <DxColumn |
| 20 | + caption="Employee" |
| 21 | + cssClass="employee__cell" |
| 22 | + :width="260" |
| 23 | + cellTemplate="employee-cell" |
| 24 | + /> |
| 25 | + <template #employee-cell="{ data: { data: employee} }"> |
| 26 | + <Employee |
| 27 | + :firstName="employee.First_Name" |
| 28 | + :lastName="employee.Last_Name" |
| 29 | + /> |
| 30 | + </template> |
| 31 | + <DxColumn |
| 32 | + dataField="Title" |
| 33 | + caption="Position" |
| 34 | + :width="140" |
| 35 | + /> |
| 36 | + <DxColumn |
| 37 | + dataField="Status" |
| 38 | + :minWidth="180" |
| 39 | + cellTemplate="status-cell" |
| 40 | + /> |
| 41 | + <template #status-cell="{ data: { data: employee} }"> |
| 42 | + <Status :status="employee.Status"/> |
| 43 | + </template> |
| 44 | + <DxColumn |
| 45 | + dataField="City" |
| 46 | + :width="180" |
| 47 | + /> |
| 48 | + <DxColumn |
| 49 | + dataField="State" |
| 50 | + :width="140" |
| 51 | + /> |
| 52 | + <DxColumn |
| 53 | + dataField="Email" |
| 54 | + :minWidth="200" |
| 55 | + cellTemplate="email-cell" |
| 56 | + /> |
| 57 | + <template #email-cell="{ data: { data: employee} }"> |
| 58 | + <Email :email="employee.Email"/> |
| 59 | + </template> |
| 60 | + <DxColumn |
| 61 | + name="AI Column" |
| 62 | + caption="AI Column" |
| 63 | + type="ai" |
| 64 | + cssClass="ai__cell" |
| 65 | + :ai="aiConfig" |
| 66 | + :fixed="true" |
| 67 | + fixedPosition="right" |
| 68 | + :width="180" |
| 69 | + /> |
| 70 | + </DxTreeList> |
| 71 | +</template> |
| 72 | + |
| 73 | +<script setup lang="ts"> |
| 74 | +import { DxTreeList, DxColumn, DxColumnFixing, DxScrolling, DxPaging } from 'devextreme-vue/tree-list'; |
| 75 | +import Email from './Email.vue'; |
| 76 | +import Employee from './Employee.vue'; |
| 77 | +import Status from './Status.vue'; |
| 78 | +import { type IEmployee, employees } from './data.ts'; |
| 79 | +import { aiIntegration } from './service.ts'; |
| 80 | +
|
| 81 | +const aiConfig = { |
| 82 | + prompt: 'Identify department for each employee. It should be one of the following department types: "Management", "Human Resources", "IT", "Shipping", "Support", "Sales", "Engineering". Use "Engineering" by default.', |
| 83 | + mode: 'auto' as const, |
| 84 | + noDataText: 'No data', |
| 85 | +}; |
| 86 | +
|
| 87 | +const onAIColumnRequestCreating = (e: { data: Partial<IEmployee>[] }) => { |
| 88 | + e.data = e.data.map((item) => ({ |
| 89 | + ID: item.ID, |
| 90 | + First_Name: item.First_Name, |
| 91 | + Last_Name: item.Last_Name, |
| 92 | + Title: item.Title, |
| 93 | + })); |
| 94 | +}; |
| 95 | +</script> |
| 96 | + |
| 97 | +<style scoped> |
| 98 | +#app .ai__cell { |
| 99 | + background-color: var(--dx-datagrid-row-alternation-bg); |
| 100 | +} |
| 101 | +
|
| 102 | +#app .employee__cell > div { |
| 103 | + align-items: flex-end; |
| 104 | +} |
| 105 | +</style> |
0 commit comments