11<script setup lang="ts">
22import DxDataGrid , { DxColumn , DxRowDragging , DxScrolling , DxLookup , DxSelection } from ' devextreme-vue/data-grid' ;
33import 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' ;
65import type { Task } from ' ../data' ;
76import { 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
1013let updateInProgress: Boolean = false ;
1114
1215const 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
1821const 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 >
0 commit comments