angular2-grid icon indicating copy to clipboard operation
angular2-grid copied to clipboard

Setting sizey programmatically effects the order of other grid items

Open madnaelo opened this issue 5 years ago • 1 comments

Setting sizey programmatically of one grid item effects the order of other grid items randomly. This happens only if the items are already displayed.

For reproducing: Use demo source from angular2-grid. And add the following methods with some event of your choice:

      expandWidget(myWidget: any) {
          myWidget.gridItemConfig.sizey = 10;
      }

      collapseWidget(myWidget: any) {
          myWidget.gridItemConfig.sizey = 1;
      }

madnaelo avatar May 29 '20 10:05 madnaelo

I have employed a workaround fix for that. That is, disable the collision detection method.

expandWidget(myWidget: any) {
    // disable the collision detection of angular2-grid's library
    const getCollisionMethod = NgGrid.prototype['_getCollisions'];
    NgGrid.prototype['_getCollisions'] =
      function (pos: NgGridItemPosition, dims: NgGridItemSize) {
        return [];
      }

    // your logic
    myWidget.gridItemConfig.sizey = 10;

    // re-enable the collision detection
    setTimeout(() => {
        NgGrid.prototype['_getCollisions'] = getCollisionMethod;
    }, 100);
}

NOTE: this is only suitable for expand/collapse type of functionality. While For resize and drag/drop it might cause other problems

madnaelo avatar May 29 '20 18:05 madnaelo