ManifestWebDesign / angular-gridster

An implementation of gridster-like widgets for Angular JS
http://manifestwebdesign.github.io/angular-gridster/
MIT License
966 stars 395 forks source link

Force layout algorithm #462

Open amergin opened 7 years ago

amergin commented 7 years ago

Is it possible to force the layout algorithm to retrigger? I asked in https://github.com/ManifestWebDesign/angular-gridster/issues/458 whether it's possible to toggle the visibility of the items. As a continuation, it would be ideal to retrigger the layout algorithm to rearrange the items in the grid to take up the space freed from the hidden items.

coreen commented 7 years ago

The way I've forced the layout algorithm to retrigger is using the following code snippet:

var temp = $scope.items;
$scope.items = [];
$timeout(function() {
    $scope.items = temp;
});

which utilizes the fact that any updates to $scope.items will trigger a $digest cycle to occur. The $timeout call with no time specified ensures that the $digest cycle is triggered before the reset of items.