Skip to content

Commit cb5b7a4

Browse files
Add Vue implementation
1 parent 2b5b8e4 commit cb5b7a4

File tree

3 files changed

+108
-18
lines changed

3 files changed

+108
-18
lines changed

Vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
"vitest": "^0.25.6",
4040
"vue-tsc": "^1.0.12"
4141
}
42-
}
42+
}

Vue/src/components/HomeContent.vue

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,70 @@
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+
DxPager,
7+
DxPaging,
8+
type DxDataGridTypes,
9+
} from 'devextreme-vue/data-grid';
10+
11+
import { employees } from '../data';
12+
13+
const allowedPageSizes = [5, 10, 20];
614
7-
const props = defineProps({
8-
text: String,
9-
});
10-
const count = ref(0);
11-
const buttonText = computed<string>(
12-
() => `Click ${props.text}: ${count.value}`
13-
);
14-
function clickHandler() {
15-
count.value += 1;
16-
}
15+
const onContextMenuPreparing = (e: DxDataGridTypes.ContextMenuPreparingEvent): void => {
16+
if (e.row?.rowType === 'data') {
17+
const rowIndex = e.row.rowIndex;
18+
if (e.rowIndex === undefined) return;
19+
e.items = [
20+
{
21+
text: 'edit',
22+
onItemClick(): void {
23+
e.component.editRow(rowIndex);
24+
},
25+
},
26+
{
27+
text: 'insert',
28+
onItemClick: async(): Promise<void> => {
29+
await e.component.addRow();
30+
},
31+
},
32+
{
33+
text: 'delete',
34+
onItemClick(): void {
35+
e.component.deleteRow(rowIndex);
36+
},
37+
},
38+
];
39+
}
40+
};
1741
</script>
1842
<template>
1943
<div>
20-
<DxButton
21-
:text="buttonText"
22-
@click="clickHandler"
23-
/>
44+
<DxDataGrid
45+
id="gridContainer"
46+
:data-source="employees"
47+
key-expr="ID"
48+
@context-menu-preparing="onContextMenuPreparing"
49+
>
50+
<DxColumn data-field="FirstName" />
51+
<DxColumn data-field="LastName" />
52+
<DxColumn data-field="Title" />
53+
<DxColumn data-field="City" />
54+
<DxColumn data-field="Country" />
55+
56+
<DxPaging :page-size="10" />
57+
<DxPager
58+
:visible="true"
59+
:allowed-page-sizes="allowedPageSizes"
60+
:show-page-size-selector="true"
61+
/>
62+
<DxEditing
63+
mode="row"
64+
:allow-updating="true"
65+
:allow-deleting="true"
66+
:allow-adding="true"
67+
/>
68+
</DxDataGrid>
2469
</div>
2570
</template>

Vue/src/data.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export interface Employee {
2+
ID: number;
3+
FirstName: string;
4+
LastName: string;
5+
City: string;
6+
}
7+
8+
export const employees = [
9+
{
10+
ID: 1,
11+
FirstName: 'John',
12+
LastName: 'Heart',
13+
City: 'Los Angeles',
14+
},
15+
{
16+
ID: 2,
17+
FirstName: 'Olivia',
18+
LastName: 'Peyton',
19+
City: 'Los Angeles',
20+
},
21+
{
22+
ID: 3,
23+
FirstName: 'Robert',
24+
LastName: 'Reagan',
25+
City: 'Bentonville',
26+
},
27+
{
28+
ID: 4,
29+
FirstName: 'Greta',
30+
LastName: 'Sims',
31+
City: 'Atlanta',
32+
},
33+
{
34+
ID: 5,
35+
FirstName: 'Brett',
36+
LastName: 'Wade',
37+
City: 'Reno',
38+
},
39+
{
40+
ID: 6,
41+
FirstName: 'Sandra',
42+
LastName: 'Johnson',
43+
City: 'Miami',
44+
},
45+
];

0 commit comments

Comments
 (0)