Skip to content

Commit 932ef3d

Browse files
Restore Vue HomeContent.vue
1 parent 797fc43 commit 932ef3d

1 file changed

Lines changed: 50 additions & 21 deletions

File tree

Vue/src/components/HomeContent.vue

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,57 @@
11
<script setup lang="ts">
2-
import { computed, ref } from 'vue';
3-
42
import 'devextreme/dist/css/dx.material.blue.light.compact.css';
5-
import DxButton from 'devextreme-vue/button';
3+
import {
4+
DxDataGrid,
5+
DxColumn,
6+
DxEditing,
7+
DxLookup,
8+
} from 'devextreme-vue/data-grid';
9+
import type { DxDataGridTypes } from 'devextreme-vue/data-grid';
10+
import type { ValueChangedEvent } from 'devextreme/ui/lookup';
11+
import type { Customer, Employee } from '../types';
12+
import { customers, employees } from '../data';
13+
14+
const onEditorPreparing = (
15+
e: DxDataGridTypes.EditorPreparingEvent<Employee, number>
16+
): void => {
17+
if (e.parentType === 'dataRow' && e.dataField === 'CustomerID') {
18+
e.editorOptions.onValueChanged = function(ev: ValueChangedEvent): void {
19+
const selectedItem = ev.component.option('selectedItem') as Customer;
20+
if (!selectedItem || !e.setValue) return;
21+
e.setValue(selectedItem);
22+
};
23+
}
24+
};
625
7-
const props = defineProps({
8-
text: {
9-
type: String,
10-
default: 'count',
11-
},
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-
}
26+
const setCellValue = (rowData: Employee, value: Customer): void => {
27+
if (!rowData || !value) return;
28+
rowData.CustomerID = value.CustomerID;
29+
rowData.Address = value.Address;
30+
rowData.Phone = value.Phone;
31+
};
2032
</script>
33+
2134
<template>
22-
<div>
23-
<DxButton
24-
:text="buttonText"
25-
@click="clickHandler"
35+
<DxDataGrid
36+
:data-source="employees"
37+
@editor-preparing="onEditorPreparing"
38+
>
39+
<DxEditing
40+
:allow-updating="true"
41+
:allow-adding="true"
2642
/>
27-
</div>
43+
<DxColumn
44+
caption="Name"
45+
data-field="CustomerID"
46+
:set-cell-value="setCellValue"
47+
>
48+
<DxLookup
49+
:data-source="customers"
50+
value-expr="CustomerID"
51+
display-expr="CustomerName"
52+
/>
53+
</DxColumn>
54+
<DxColumn data-field="Address"/>
55+
<DxColumn data-field="Phone"/>
56+
</DxDataGrid>
2857
</template>

0 commit comments

Comments
 (0)