@@ -96,8 +96,18 @@ export class Example16 {
9696 cancelEditOnDrag : true ,
9797 hideRowMoveShadow : false ,
9898 width : 30 ,
99- onBeforeMoveRows : this . onBeforeMoveRow . bind ( this ) ,
100- onMoveRows : this . onMoveRows . bind ( this ) ,
99+ // you can provide your own `onBeforeMoveRows` and/or `onMoveRows` implementation
100+ // or use the default implementation, however the default won't work with Tree Data
101+ // onBeforeMoveRows: () => {},
102+ // onMoveRows: () => {},
103+ // you can provide your own `onBeforeMoveRows` and/or `onMoveRows` implementation
104+ // or use the default implementation, however the default won't work with Tree Data
105+ // onBeforeMoveRows: () => {},
106+ // onMoveRows: () => {},
107+ onAfterMoveRows : ( _e , args ) => {
108+ // update dataset for the ms-select list to be updated
109+ this . dataset = args . updatedItems ;
110+ } ,
101111
102112 // you can change the move icon position of any extension (RowMove, RowDetail or RowSelector icon)
103113 // note that you might have to play with the position when using multiple extension
@@ -137,74 +147,6 @@ export class Example16 {
137147 this . dataset = mockDataset ;
138148 }
139149
140- onBeforeMoveRow ( e : MouseEvent | TouchEvent , data : { rows : number [ ] ; insertBefore : number } ) {
141- for ( const rowIdx of data . rows ) {
142- // no point in moving before or after itself
143- if (
144- rowIdx === data . insertBefore ||
145- ( rowIdx === data . insertBefore - 1 && data . insertBefore - 1 !== this . aureliaGrid . dataView . getItemCount ( ) )
146- ) {
147- e . preventDefault ( ) ; // OR eventData.preventDefault();
148- return false ;
149- }
150- }
151- return true ;
152- }
153-
154- onMoveRows ( _e : MouseEvent | TouchEvent , args : any ) {
155- // rows and insertBefore references,
156- // note that these references are assuming that the dataset isn't filtered at all
157- // which is not always the case so we will recalcualte them and we won't use these reference afterward
158- const rows = args . rows as number [ ] ;
159- const insertBefore = args . insertBefore ;
160- const extractedRows : number [ ] = [ ] ;
161-
162- // when moving rows, we need to cancel any sorting that might happen
163- // we can do this by providing an undefined sort comparer
164- // which basically destroys the current sort comparer without resorting the dataset, it basically keeps the previous sorting
165- this . aureliaGrid . dataView . sort ( undefined as any , true ) ;
166-
167- // the dataset might be filtered/sorted,
168- // so we need to get the same dataset as the one that the SlickGrid DataView uses
169- const tmpDataset = this . aureliaGrid . dataView . getItems ( ) ;
170- const filteredItems = this . aureliaGrid . dataView . getFilteredItems ( ) ;
171-
172- const itemOnRight = this . aureliaGrid . dataView . getItem ( insertBefore ) ;
173- const insertBeforeFilteredIdx = itemOnRight
174- ? this . aureliaGrid . dataView . getIdxById ( itemOnRight . id )
175- : this . aureliaGrid . dataView . getItemCount ( ) ;
176-
177- const filteredRowItems : any [ ] = [ ] ;
178- rows . forEach ( ( row ) => filteredRowItems . push ( filteredItems [ row ] ) ) ;
179- const filteredRows = filteredRowItems . map ( ( item ) => this . aureliaGrid . dataView . getIdxById ( item . id ) ) ;
180-
181- const left = tmpDataset . slice ( 0 , insertBeforeFilteredIdx ) ;
182- const right = tmpDataset . slice ( insertBeforeFilteredIdx , tmpDataset . length ) ;
183-
184- // convert into a final new dataset that has the new order
185- // we need to resort with
186- rows . sort ( ( a : number , b : number ) => a - b ) ;
187- for ( const filteredRow of filteredRows ) {
188- if ( filteredRow ) {
189- extractedRows . push ( tmpDataset [ filteredRow ] ) ;
190- }
191- }
192- filteredRows . reverse ( ) ;
193- for ( const row of filteredRows ) {
194- if ( row !== undefined && insertBeforeFilteredIdx !== undefined ) {
195- if ( row < insertBeforeFilteredIdx ) {
196- left . splice ( row , 1 ) ;
197- } else {
198- right . splice ( row - insertBeforeFilteredIdx , 1 ) ;
199- }
200- }
201- }
202-
203- // final updated dataset, we need to overwrite the DataView dataset (and our local one) with this new dataset that has a new order
204- const finalDataset = left . concat ( extractedRows . concat ( right ) ) ;
205- this . dataset = finalDataset ; // update dataset and re-render the grid
206- }
207-
208150 hideDurationColumnDynamically ( ) {
209151 // -- you can hide by one Id or multiple Ids:
210152 // hideColumnById(id, options), hideColumnByIds([ids], options)
0 commit comments