Skip to content

Commit d781733

Browse files
Fix: Vue implementation, lint, and build
1 parent 25d5410 commit d781733

File tree

12 files changed

+138
-205
lines changed

12 files changed

+138
-205
lines changed

Vue/orig_index.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

Vue/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Vue/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"devextreme": "25.1.3",
16+
"devextreme-aspnet-data-nojquery": "^5.1.0",
1617
"devextreme-vue": "25.1.3",
1718
"vue": "^3.2.45",
1819
"vue-router": "^4.1.6"

Vue/src/assets/orig_main.css

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<script setup lang="ts">
22
import DxDataGrid, { DxColumn, DxRowDragging, DxScrolling, DxLookup, DxSelection } from 'devextreme-vue/data-grid';
33
import type dxDataGrid from 'devextreme/ui/data_grid';
4-
import type { RowDraggingStartEvent, RowDraggingAddEvent, Column, Row } from 'devextreme/ui/data_grid';
5-
import CustomStore from "devextreme/data/custom_store";
4+
import type { DxDataGridTypes } from 'devextreme-vue/data-grid';
65
import type { Task } from '../data';
76
import { priorities } from '../data';
8-
import DataSource from "devextreme/data/data_source";
7+
import notify from 'devextreme/ui/notify';
8+
import DataSource from 'devextreme/data/data_source';
9+
import CustomStore from 'devextreme/data/custom_store';
10+
11+
type CellValue = Task[keyof Task] | string | undefined;
912
1013
let updateInProgress: Boolean = false;
1114
1215
const props = defineProps({
13-
tasksStore: CustomStore,
14-
status: Number,
15-
shouldClearSelection: Boolean,
16+
tasksStore: { type: CustomStore, required: true },
17+
status: { type: Number, default: 0 },
18+
shouldClearSelection: { type: Boolean, default: false },
1619
});
1720
1821
const filterExpr = ['Status', '=', props.status];
@@ -22,49 +25,52 @@ const dataSource = new DataSource({
2225
reshapeOnPush: true,
2326
});
2427
25-
function getVisibleRowValues(rowsData: Task[], grid: dxDataGrid) {
26-
const visibleColumns = grid.getVisibleColumns();
27-
const selectedData = rowsData.map((rowData: Task) => {
28-
const visibleValues: any = {};
29-
visibleColumns.forEach((column: Column) => {
30-
if (column.dataField)
31-
visibleValues[column.dataField] = getVisibleCellValue(column, rowData);
32-
});
33-
return visibleValues;
28+
function getVisibleRowValues(rowsData: Task[], grid: dxDataGrid): Record<string, CellValue>[] {
29+
const visibleColumns = grid.getVisibleColumns();
30+
const selectedData = rowsData.map((rowData: Task) => {
31+
const visibleValues: Record<string, CellValue> = {};
32+
visibleColumns.forEach((column: DxDataGridTypes.Column) => {
33+
if (column.dataField)
34+
{ visibleValues[column.dataField] = getVisibleCellValue(column, rowData); }
3435
});
35-
return selectedData;
36+
return visibleValues;
37+
});
38+
return selectedData;
3639
}
3740
38-
function getVisibleCellValue(column: Column, rowData: Task) {
39-
if (column.dataField) {
40-
const propKey = column.dataField as (keyof Task);
41-
const cellValue = rowData[propKey];
42-
return column.lookup && column.lookup.calculateCellValue ? column.lookup.calculateCellValue(cellValue) : cellValue;
43-
}
41+
function getVisibleCellValue(column: DxDataGridTypes.Column, rowData: Task): CellValue {
42+
if (column.dataField) {
43+
const propKey = column.dataField as keyof Task;
44+
const cellValue = rowData[propKey];
45+
return column?.lookup?.calculateCellValue
46+
? column.lookup.calculateCellValue(cellValue) as CellValue
47+
: cellValue as CellValue;
48+
}
49+
return undefined;
4450
}
4551
46-
function canDrag(e: RowDraggingStartEvent) {
52+
function canDrag(e: DxDataGridTypes.RowDraggingStartEvent): boolean {
4753
if (updateInProgress) return false;
4854
const visibleRows = e.component.getVisibleRows();
49-
return visibleRows.some((r: Row) => r.isSelected && r.rowIndex === e.fromIndex);
55+
return visibleRows.some((r: DxDataGridTypes.Row) => r.isSelected && r.rowIndex === e.fromIndex);
5056
}
5157
52-
function onDragStart(e: RowDraggingStartEvent) {
58+
function onDragStart(e: DxDataGridTypes.RowDraggingStartEvent): void {
5359
const selectedData: Task[] = e.component.getSelectedRowsData();
5460
e.itemData = getVisibleRowValues(selectedData, e.component);
5561
e.cancel = !canDrag(e);
5662
}
5763
58-
function onAdd(e: RowDraggingAddEvent) {
64+
async function onAdd(e: DxDataGridTypes.RowDraggingAddEvent): Promise<void> {
5965
const fromGrid = e.fromComponent as dxDataGrid;
6066
const toGrid = e.toComponent as dxDataGrid;
6167
const selectedRowKeys: (keyof Task)[] = fromGrid.getSelectedRowKeys();
6268
const updateProcess: (Promise<any> | undefined)[] = [];
6369
const changes: any[] = [];
6470
6571
updateInProgress = true;
66-
fromGrid.beginCustomLoading("Loading...");
67-
toGrid.beginCustomLoading("Loading...");
72+
fromGrid.beginCustomLoading('Loading...');
73+
toGrid.beginCustomLoading('Loading...');
6874
for (let key of selectedRowKeys) {
6975
const values = { Status: e.toData };
7076
updateProcess.push(props.tasksStore?.update(key, values));
@@ -74,17 +80,21 @@ function onAdd(e: RowDraggingAddEvent) {
7480
data: values,
7581
});
7682
}
77-
Promise.all(updateProcess).then(() => {
78-
props.tasksStore?.push(changes);
83+
try {
84+
await Promise.all(updateProcess);
85+
let gridStore = props.tasksStore;
86+
gridStore?.push(changes);
7987
fromGrid.endCustomLoading();
8088
toGrid.endCustomLoading();
8189
updateInProgress = false;
8290
8391
fromGrid.clearSelection();
8492
if (!props.shouldClearSelection) {
85-
toGrid.selectRows(selectedRowKeys, true);
93+
await toGrid.selectRows(selectedRowKeys, true);
8694
}
87-
});
95+
} catch (error: unknown) {
96+
notify(error, 'error', 1000);
97+
}
8898
}
8999
90100
</script>
@@ -97,8 +107,8 @@ function onAdd(e: RowDraggingAddEvent) {
97107
>
98108
<DxRowDragging
99109
:data="status"
100-
:on-add="onAdd"
101-
:on-drag-start="onDragStart"
110+
:on-add="onAdd as unknown as () => void"
111+
:on-drag-start="onDragStart as () => void"
102112
drag-template="dragItems"
103113
group="tasksGroup"
104114
/>
@@ -108,11 +118,11 @@ function onAdd(e: RowDraggingAddEvent) {
108118
<tbody>
109119
<tr
110120
v-for="(item, rowIndex) in data.itemData"
111-
v-bind:key="'row' + rowIndex"
121+
:key="'row' + rowIndex"
112122
>
113123
<td
114124
v-for="(key, dataIndex) in Object.keys(item)"
115-
v-bind:key="'key' + dataIndex"
125+
:key="'key' + dataIndex"
116126
>
117127
{{ item[key] }}
118128
</td>
@@ -145,4 +155,4 @@ function onAdd(e: RowDraggingAddEvent) {
145155
/>
146156

147157
</DxDataGrid>
148-
</template>
158+
</template>

Vue/src/components/HomeContent.vue

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,86 @@
11
<script setup lang="ts">
2-
import { computed, ref } from 'vue';
2+
import { ref } from 'vue';
33
44
import 'devextreme/dist/css/dx.material.blue.light.compact.css';
5-
import DxButton from 'devextreme-vue/button';
5+
import type CustomStore from 'devextreme/data/custom_store';
6+
import { createStore } from 'devextreme-aspnet-data-nojquery';
7+
import DxSwitch from 'devextreme-vue/switch';
8+
import Grid from './CustomGrid.vue';
69
7-
const props = defineProps({
8-
text: {
9-
type: String,
10-
default: 'count',
10+
const shouldClearSelection = ref(false);
11+
12+
const url = 'https://js.devexpress.com/Demos/Mvc/api/DnDBetweenGrids';
13+
14+
const tasksStore: CustomStore = createStore({
15+
key: 'ID',
16+
loadUrl: `${url}/Tasks`,
17+
updateUrl: `${url}/UpdateTask`,
18+
onBeforeSend(_method, ajaxOptions) {
19+
ajaxOptions.xhrFields = { withCredentials: true };
1120
},
1221
});
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-
}
2022
</script>
2123
<template>
2224
<div>
23-
<DxButton
24-
:text="buttonText"
25-
@click="clickHandler"
26-
/>
25+
<div className="demo-header">
26+
<h3>DataGrid - Select multiple items and drag'n'drop</h3>
27+
<div id="toggle-container">
28+
<span>Clear selection after drop</span>
29+
<DxSwitch
30+
id="clearAfterDropSwitch"
31+
v-model:value="shouldClearSelection"
32+
/>
33+
</div>
34+
</div>
35+
<div class="tables">
36+
<Grid
37+
:tasks-store="tasksStore"
38+
:status="1"
39+
:should-clear-selection="shouldClearSelection"
40+
class="column"
41+
/>
42+
<Grid
43+
:tasks-store="tasksStore"
44+
:status="2"
45+
:should-clear-selection="shouldClearSelection"
46+
class="column"
47+
/>
48+
</div>
2749
</div>
2850
</template>
51+
<style scoped>
52+
.demo-container {
53+
margin: 50px 50px;
54+
width: 90vh;
55+
}
56+
.demo-header {
57+
display: flex;
58+
justify-content: space-between;
59+
}
60+
#toggle-container {
61+
padding-top: 20px;
62+
}
63+
#clearAfterDropSwitch {
64+
vertical-align: text-bottom;
65+
}
66+
#toggle-container span {
67+
padding-right: 10px;
68+
}
69+
:global(.drag-container) {
70+
padding: 10px;
71+
}
72+
:global(.drag-container td) {
73+
padding: 0px 10px 0px 10px;
74+
}
75+
.tables {
76+
display: flex;
77+
}
78+
.column:first-child {
79+
width: 50%;
80+
padding-right: 15px;
81+
}
82+
.column:last-child {
83+
width: 50%;
84+
padding-left: 15px;
85+
}
86+
</style>

0 commit comments

Comments
 (0)