File tree 4 files changed +262
-231
lines changed
packages/components/src/components/hds/table
tests/integration/components/hds/table
4 files changed +262
-231
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,11 @@ export default class HdsTable extends Component<HdsTableSignature> {
300
300
) ;
301
301
302
302
if ( selectionKey ) {
303
+ // Remove any existing item with the same `selectionKey` identifier (this may occur if the model is updated and the rows re-rendered)
304
+ this . _selectableRows = this . _selectableRows . filter (
305
+ ( row ) : boolean => row . selectionKey !== selectionKey
306
+ ) ;
307
+ // Add the new item
303
308
this . _selectableRows . push ( { selectionKey, checkbox } ) ;
304
309
}
305
310
this . setSelectAllState ( ) ;
@@ -314,22 +319,6 @@ export default class HdsTable extends Component<HdsTableSignature> {
314
319
this . _selectableRows . map ( ( row ) : string => row . selectionKey )
315
320
) ;
316
321
317
- // Fix for selectableRows state not being maintained properly when model updates:
318
- // Delete the first row with the given selection key you find from the selectableRows array
319
- // Search for the index of the row to delete. If found, delete it.
320
- // (Fixes issue of not rows not being properly selectable including "select all" functionality)
321
- const rowToDeleteIndex = this . _selectableRows . findIndex (
322
- ( row ) : boolean => row . selectionKey === selectionKey
323
- ) ;
324
-
325
- if ( rowToDeleteIndex > - 1 ) {
326
- this . _selectableRows . splice ( rowToDeleteIndex , 1 ) ;
327
- }
328
-
329
- // ORIGINAL:
330
- // this._selectableRows = this._selectableRows.filter(
331
- // (row): boolean => row.selectionKey !== selectionKey
332
- // );
333
322
this . setSelectAllState ( ) ;
334
323
}
335
324
Original file line number Diff line number Diff line change @@ -35,6 +35,15 @@ export default class extends Controller {
35
35
. sort ( ( ) => Math . random ( ) - 0.5 ) ;
36
36
}
37
37
38
+ @action dirtyModelWithLessRows ( ) {
39
+ this . lyrics = this . lyrics
40
+ // Deep copy to destroy references
41
+ . map ( ( r ) => ( { ...r } ) )
42
+ // Randomly sort to see what happens in this case
43
+ . sort ( ( ) => Math . random ( ) - 0.5 )
44
+ . filter ( ( row ) => row . key !== 'five' ) ;
45
+ }
46
+
38
47
printSelection = ( selection ) =>
39
48
console . log ( 'Printing selection:' , selection . selectedRowsKeys ) ;
40
49
}
Original file line number Diff line number Diff line change 22
22
23
23
<Shw::Text::H2 >This will work until you click the "Force new data" button</Shw::Text::H2 >
24
24
25
- <Hds::Button @text =" Force new data" {{ on " click" this.dirtyModel }} />
25
+ <p >
26
+ <Hds::Button @text =" Force new data" {{ on " click" this.dirtyModel }} @isInline ={{ true }} />
27
+ <Hds::Button @text =" Force new data with fewer rows" {{ on " click" this.dirtyModelWithLessRows }} @isInline ={{ true }} />
28
+ </p >
26
29
27
30
<Hds::Table
28
31
@model ={{ this.lyrics }}
You can’t perform that action at this time.
0 commit comments