File tree Expand file tree Collapse file tree 2 files changed +48
-5
lines changed
e2e/testcafe-devextreme/tests/dataGrid/focus
packages/devextreme/js/__internal/grids/grid_core/focus Expand file tree Collapse file tree 2 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -241,6 +241,37 @@ test('DataGrid - FilterRow cell loses focus when focusedRowEnabled is true and e
241
241
} ) ;
242
242
} ) ;
243
243
244
+ test ( 'DataGrid - FocusedRowChanged event isnt raised when the push API is used to remove the last row (T1261532)' , async ( t ) => {
245
+ const grid = new DataGrid ( GRID_SELECTOR ) ;
246
+
247
+ await t
248
+ . expect ( grid . option ( 'focusedRowKey' ) )
249
+ . eql ( null )
250
+ . expect ( grid . option ( 'focusedRowIndex' ) )
251
+ . eql ( - 1 ) ;
252
+ } ) . before ( async ( ) => createWidget ( 'dxDataGrid' , {
253
+ dataSource : {
254
+ store : {
255
+ data : [
256
+ {
257
+ id : 1 ,
258
+ name : 'Item 1 ' ,
259
+ } ,
260
+ ] ,
261
+ type : 'array' ,
262
+ key : 'id' ,
263
+ } ,
264
+ reshapeOnPush : true ,
265
+ } ,
266
+ keyExpr : 'id' ,
267
+ showBorders : true ,
268
+ focusedRowEnabled : true ,
269
+ focusedRowKey : 1 ,
270
+ onInitialized ( e ) {
271
+ e . component ?. getDataSource ( ) . store ( ) . push ( [ { type : 'remove' , key : 1 } ] ) ;
272
+ } ,
273
+ } ) ) ;
274
+
244
275
[ 'onFocusedRowChanged' , 'onFocusedRowChanging' ] . forEach ( ( event ) => {
245
276
test ( `Focus should be preserved on datagrid when rowsview repaints in ${ event } event (T1224663)` , async ( t ) => {
246
277
const dataGrid = new DataGrid ( '#container' ) ;
Original file line number Diff line number Diff line change @@ -82,16 +82,28 @@ export class FocusController extends core.ViewController {
82
82
if ( ! this . option ( 'focusedRowEnabled' ) ) {
83
83
return ;
84
84
}
85
+ const isEmptyData = this . getDataController ( ) . isEmpty ( ) ;
86
+ const currentIndex = this . _getCurrentFocusRowIndex ( isEmptyData , index ) ;
85
87
86
- index = index !== undefined ? index : this . option ( 'focusedRowIndex' ) ;
87
-
88
- if ( index < 0 ) {
89
- if ( this . isAutoNavigateToFocusedRow ( ) ) {
88
+ if ( currentIndex < 0 ) {
89
+ if ( isEmptyData || this . isAutoNavigateToFocusedRow ( ) ) {
90
90
this . _resetFocusedRow ( ) ;
91
91
}
92
92
} else {
93
- this . _focusRowByIndexCore ( index , operationTypes ) ;
93
+ this . _focusRowByIndexCore ( currentIndex , operationTypes ) ;
94
+ }
95
+ }
96
+
97
+ private _getCurrentFocusRowIndex ( isEmptyData , index ?) : number {
98
+ let currentIndex = index ;
99
+ if ( currentIndex === undefined ) {
100
+ if ( isEmptyData ) {
101
+ currentIndex = - 1 ;
102
+ } else {
103
+ currentIndex = this . option ( 'focusedRowIndex' ) ;
104
+ }
94
105
}
106
+ return currentIndex ;
95
107
}
96
108
97
109
private _focusRowByIndexCore ( index , operationTypes ) {
You can’t perform that action at this time.
0 commit comments