Search code examples
javascriptangularjsangular-ui-grid

Emptying ui-grid on button click


Is there any way to completely empty a ui-grid (filters,data, column and all)?

I'm trying to empty the grid on button-click so that a new http request can be made and the result displayed using the same grid without reloading the page.

I tried $scope.gridOptions.length=0 but the data remains and on making an new request, the result gets appended to the previous result


Solution

  • To empty a ui-grid data you will need to reinitialize via any array syntax.

    $scope.gridOptions.data= [];
    

    To clear all filters ,columns, you will need to later reinitialize the gridOptions itself via object literal syntax.

    $scope.gridOptions= {};