@@ -210,6 +210,8 @@ export class GridStack {
210
210
private _isAutoCellHeight : boolean ;
211
211
/** @internal track event binding to window resize so we can remove */
212
212
private _windowResizeBind : ( ) => GridStack ;
213
+ /** @internal true when loading items to insert first rather than append */
214
+ private _insertNotAppend : boolean ;
213
215
214
216
/**
215
217
* Construct a grid item from the given element and options
@@ -397,7 +399,11 @@ export class GridStack {
397
399
this . engine . prepareNode ( options ) ;
398
400
this . _writeAttr ( el , options ) ;
399
401
400
- this . el . appendChild ( el ) ;
402
+ if ( this . _insertNotAppend ) {
403
+ this . el . prepend ( el ) ;
404
+ } else {
405
+ this . el . appendChild ( el ) ;
406
+ }
401
407
402
408
// similar to makeWidget() that doesn't read attr again and worse re-create a new node and loose any _id
403
409
this . _prepareElement ( el , true , options ) ;
@@ -467,6 +473,7 @@ export class GridStack {
467
473
**/
468
474
public load ( layout : GridStackWidget [ ] , addAndRemove : boolean | ( ( g : GridStack , w : GridStackWidget , add : boolean ) => GridItemHTMLElement ) = true ) : GridStack {
469
475
let items = GridStack . Utils . sort ( layout , - 1 , this . _prevColumn || this . opts . column ) ;
476
+ this . _insertNotAppend = true ; // since create in reverse order...
470
477
471
478
// if we're loading a layout into 1 column (_prevColumn is set only when going to 1) and items don't fit, make sure to save
472
479
// the original wanted layout so we can scale back up correctly #1471
@@ -503,6 +510,7 @@ export class GridStack {
503
510
let sub = item . el . querySelector ( '.grid-stack' ) as GridHTMLElement ;
504
511
if ( sub && sub . gridstack ) {
505
512
sub . gridstack . load ( ( w . subGrid as GridStackOptions ) . children ) ; // TODO: support updating grid options ?
513
+ this . _insertNotAppend = true ; // got reset by above call
506
514
}
507
515
}
508
516
} else if ( addAndRemove ) {
@@ -523,7 +531,7 @@ export class GridStack {
523
531
524
532
// after commit, clear that flag
525
533
delete this . _ignoreLayoutsNodeChange ;
526
-
534
+ delete this . _insertNotAppend ;
527
535
return this ;
528
536
}
529
537
0 commit comments