@@ -6,9 +6,10 @@ import {
66} from '@angular/platform-browser' ;
77import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' ;
88import { DxNumberBoxComponent , DxNumberBoxModule , DxCheckBoxModule } from 'devextreme-angular' ;
9- import { DataSourceOptions } from 'devextreme-angular/common/data' ;
9+ import { DataSource , ArrayStore } from 'devextreme-angular/common/data' ;
1010
1111import { DxDataGridComponent , DxDataGridModule , DxDataGridTypes } from 'devextreme-angular/ui/data-grid' ;
12+ import { type Task , Service } from './app.service' ;
1213
1314if ( ! / l o c a l h o s t / . test ( document . location . host ) ) {
1415 enableProdMode ( ) ;
@@ -24,15 +25,14 @@ if (window && window.config?.packageConfigPaths) {
2425 selector : 'demo-app' ,
2526 templateUrl : `.${ modulePrefix } /app.component.html` ,
2627 styleUrls : [ `.${ modulePrefix } /app.component.css` ] ,
28+ providers : [ Service ] ,
2729 preserveWhitespaces : true ,
2830} )
2931export class AppComponent {
3032 @ViewChild ( DxDataGridComponent , { static : false } ) dataGrid : DxDataGridComponent ;
3133
3234 @ViewChild ( DxNumberBoxComponent , { static : false } ) numberBox : DxNumberBoxComponent ;
3335
34- isReady : boolean ;
35-
3636 taskSubject : string ;
3737
3838 taskDetailsHtml : SafeHtml ;
@@ -45,24 +45,7 @@ export class AppComponent {
4545
4646 autoNavigateToFocusedRow = true ;
4747
48- dataSource : DataSourceOptions = {
49- store : {
50- type : 'odata' ,
51- version : 2 ,
52- key : 'Task_ID' ,
53- url : 'https://js.devexpress.com/Demos/DevAV/odata/Tasks' ,
54- } ,
55- expand : 'ResponsibleEmployee' ,
56- select : [
57- 'Task_ID' ,
58- 'Task_Subject' ,
59- 'Task_Start_Date' ,
60- 'Task_Status' ,
61- 'Task_Description' ,
62- 'Task_Completion' ,
63- 'ResponsibleEmployee/Employee_Full_Name' ,
64- ] ,
65- } ;
48+ dataSource : DataSource ;
6649
6750 columns : DxDataGridTypes . Column [ ] = [
6851 {
@@ -87,9 +70,16 @@ export class AppComponent {
8770 } ,
8871 ] ;
8972
90- constructor ( private sanitizer : DomSanitizer ) { }
73+ constructor ( private sanitizer : DomSanitizer , service : Service ) {
74+ this . dataSource = new DataSource ( {
75+ store : new ArrayStore ( {
76+ data : service . getTasks ( ) ,
77+ key : 'Task_ID' ,
78+ } ) ,
79+ } ) ;
80+ }
9181
92- onFocusedRowChanging ( e ) {
82+ onFocusedRowChanging ( e : DxDataGridTypes . FocusedRowChangingEvent ) {
9383 const rowsCount = e . component . getVisibleRows ( ) . length ;
9484 const pageCount = e . component . pageCount ( ) ;
9585 const pageIndex = e . component . pageIndex ( ) ;
@@ -108,11 +98,12 @@ export class AppComponent {
10898 }
10999 }
110100
111- onFocusedRowChanged ( { row : { data } } : DxDataGridTypes . FocusedRowChangedEvent ) {
112- this . taskSubject = data . Task_Subject ;
113- this . taskDetailsHtml = this . sanitizer . bypassSecurityTrustHtml ( data . Task_Description ) ;
114- this . taskStatus = data . Task_Status ;
115- this . taskProgress = data . Task_Completion ? `${ data . Task_Completion } %` : '' ;
101+ onFocusedRowChanged ( e : DxDataGridTypes . FocusedRowChangedEvent < Task , number > ) {
102+ const data = e . row ?. data ;
103+ this . taskSubject = data ?. Task_Subject ?? '' ;
104+ this . taskDetailsHtml = this . sanitizer . bypassSecurityTrustHtml ( data ?. Task_Description ?? '' ) ;
105+ this . taskStatus = data ?. Task_Status ?? '' ;
106+ this . taskProgress = data ?. Task_Completion ? `${ data ?. Task_Completion } %` : '' ;
116107 }
117108}
118109
0 commit comments