File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -146,14 +146,15 @@ export class Utils {
146146 * Sorts array of nodes
147147 * @param nodes array to sort
148148 * @param dir 1 for asc, -1 for desc (optional)
149- * @param width width of the grid. If undefined the width will be calculated automatically (optional).
149+ * @param column number of columns in the grid. If undefined columns will be calculated automatically (optional).
150150 **/
151151 static sort ( nodes : GridStackNode [ ] , dir : 1 | - 1 = 1 , column ?: number ) : GridStackNode [ ] {
152152 column = column || nodes . reduce ( ( col , n ) => Math . max ( n . x + n . w , col ) , 0 ) || 12 ;
153- if ( dir === - 1 )
154- return nodes . sort ( ( a , b ) => ( ( b . x ?? 1000 ) + ( b . y ?? 1000 ) * column ) - ( ( a . x ?? 1000 ) + ( a . y ?? 1000 ) * column ) ) ;
155- else
156- return nodes . sort ( ( b , a ) => ( ( b . x ?? 1000 ) + ( b . y ?? 1000 ) * column ) - ( ( a . x ?? 1000 ) + ( a . y ?? 1000 ) * column ) ) ;
153+ return nodes . sort ( ( a , b ) => {
154+ let diffY = dir * ( a . y - b . y ) ;
155+ if ( diffY === 0 ) return dir * column * ( a . x - b . x ) ;
156+ return diffY ;
157+ } ) ;
157158 }
158159
159160 /** find an item by id */
You can’t perform that action at this time.
0 commit comments