@@ -2,13 +2,14 @@ import { Component } from '@angular/core';
22import { KeyValue } from '@angular/common' ;
33import { Task , Priority , GridDataService } from 'src/app/services/grid-data.service' ;
44import * as AspNetData from 'devextreme-aspnet-data-nojquery' ;
5- import DxDataGrid , {
6- RowDraggingStartEvent , RowDraggingAddEvent , Column , Row ,
7- } from 'devextreme/ui/data_grid' ;
5+ import dxDataGrid from 'devextreme/ui/data_grid' ;
6+ import type { DxDataGridTypes } from 'devextreme-angular/ui/data-grid' ;
87import CustomStore from 'devextreme/data/custom_store' ;
98import { DataSourceOptions } from 'devextreme/data/data_source' ;
109import notify from 'devextreme/ui/notify' ;
1110
11+ type CellValue = Task [ keyof Task ] | string | undefined ;
12+
1213@Component ( {
1314 selector : 'app-root' ,
1415 templateUrl : './app.component.html' ,
@@ -36,7 +37,7 @@ export class AppComponent {
3637 key : 'ID' ,
3738 loadUrl : `${ url } /Tasks` ,
3839 updateUrl : `${ url } /UpdateTask` ,
39- onBeforeSend ( method , ajaxOptions ) {
40+ onBeforeSend ( _method , ajaxOptions ) {
4041 ajaxOptions . xhrFields = { withCredentials : true } ;
4142 } ,
4243 } ) ;
@@ -50,15 +51,15 @@ export class AppComponent {
5051 this . canDrag = this . canDrag . bind ( this ) ;
5152 }
5253
53- onDragStart ( e : any ) : void {
54+ onDragStart ( e : DxDataGridTypes . RowDraggingStartEvent ) : void {
5455 const selectedData : Task [ ] = e . component . getSelectedRowsData ( ) ;
5556 e . itemData = this . getVisibleRowValues ( selectedData , e . component ) ;
5657 e . cancel = ! this . canDrag ( e ) ;
5758 }
5859
59- async onAdd ( e : any ) : Promise < void > {
60- const fromGrid = e . fromComponent as DxDataGrid ;
61- const toGrid = e . toComponent as DxDataGrid ;
60+ async onAdd ( e : DxDataGridTypes . RowDraggingAddEvent ) : Promise < void > {
61+ const fromGrid = e . fromComponent as dxDataGrid ;
62+ const toGrid = e . toComponent as dxDataGrid ;
6263 const selectedRowKeys : ( keyof Task ) [ ] = fromGrid . getSelectedRowKeys ( ) ;
6364 const updateProcess : Promise < any > [ ] = [ ] ;
6465 const changes : any [ ] = [ ] ;
@@ -80,7 +81,6 @@ export class AppComponent {
8081
8182 try {
8283 await Promise . all ( updateProcess ) ;
83-
8484 this . tasksStore . push ( changes ) ;
8585 fromGrid . endCustomLoading ( ) ;
8686 toGrid . endCustomLoading ( ) ;
@@ -95,11 +95,11 @@ export class AppComponent {
9595 }
9696 }
9797
98- getVisibleRowValues ( rowsData : Task [ ] , grid : DxDataGrid ) : Record < string , Task [ keyof Task ] | string | undefined > [ ] {
98+ getVisibleRowValues ( rowsData : Task [ ] , grid : dxDataGrid ) : Record < string , CellValue > [ ] {
9999 const visibleColumns = grid . getVisibleColumns ( ) ;
100100 const selectedData = rowsData . map ( ( rowData : Task ) => {
101- const visibleValues : Record < string , Task [ keyof Task ] | string | undefined > = { } ;
102- visibleColumns . forEach ( ( column : Column ) => {
101+ const visibleValues : Record < string , CellValue > = { } ;
102+ visibleColumns . forEach ( ( column : DxDataGridTypes . Column ) => {
103103 if ( column . dataField ) {
104104 visibleValues [ column . dataField ] = this . getVisibleCellValue ( column , rowData ) ;
105105 }
@@ -109,22 +109,17 @@ export class AppComponent {
109109 return selectedData ;
110110 }
111111
112- getVisibleCellValue ( column : Column , rowData : Task ) : Task [ keyof Task ] | string | undefined {
113- if ( column . dataField ) {
114- const propKey = column . dataField as keyof Task ;
115- const cellValue = rowData [ propKey ] ;
116-
117- return column . lookup ?. calculateCellValue
118- ? String ( column . lookup . calculateCellValue ( cellValue ) )
119- : cellValue ;
120- }
121- return undefined ;
112+ getVisibleCellValue ( column : DxDataGridTypes . Column , rowData : Task ) : CellValue {
113+ const cellValue = rowData [ column . dataField as keyof Task ] ;
114+ return column . lookup ?. calculateCellValue
115+ ? String ( column . lookup . calculateCellValue ( cellValue ) )
116+ : cellValue ;
122117 }
123118
124- canDrag ( e : RowDraggingStartEvent ) : Row | Boolean {
119+ canDrag ( e : DxDataGridTypes . RowDraggingStartEvent ) : DxDataGridTypes . Row | Boolean {
125120 if ( this . updateInProgress ) return false ;
126121 const visibleRows = e . component . getVisibleRows ( ) ;
127- return visibleRows . some ( ( r : Row ) => r . isSelected && r . rowIndex === e . fromIndex ) ;
122+ return visibleRows . some ( ( r : DxDataGridTypes . Row ) => r . isSelected && r . rowIndex === e . fromIndex ) ;
128123 }
129124
130125 originalOrder ( a : KeyValue < number , string > , b : KeyValue < number , string > ) : number {
0 commit comments