0

This issue is very similar to this below issue: Angular js UI grid is not getting updated with new content

but, what is my problem is, on rebind, i am using different data and columns. So when i do that on button click, the grid is not refreshed.

please check this sample : http://plnkr.co/edit/NIlEiAoZbt7ZcnXDPqrb

$scope.myfunc = function() {

      alert("Rebinding the data");
        $scope.gridOptions = {};

       $scope.gridOptions.columnDefs = [
    { field:'firstName' },
    { field:'lastName' },
    { field:'company' },
    { field:'employed' }
  ];
  $scope.gridOptions.data = data2;

}; on this event, only one column (which exists on both datasets are binding properly). -- NewBuddy

Community
  • 1
  • 1
NewBuddy
  • 55
  • 1
  • 2
  • 6
  • I have now a new problem. When i dynamically push the columns to the grid for each time i re-bind the data, the new columns are getting added and old columns are still remained to the grid but as empty cells. Can some body let me know how to remove/ still show original columns only?? – NewBuddy May 31 '16 at 12:53

1 Answers1

0

I can't see data2 in your plunk and its giving error. Although, the below code should solve your problem.

$scope.gridOptions.onRegisterApi= function(gridApi) {
            $scope.gridApi = gridApi;                
};

on change of data/columns call the below function:

$scope.gridApi.grid.refresh();
Maverick
  • 454
  • 2
  • 11
  • i am binding data using json url at first and later on button click, i am binding my static data. When i click the rebind button, only the common column (company) data only reflecting. i tried to add your suggestions but no result as of now – NewBuddy May 25 '16 at 11:47
  • Hi, Maverick, thanks for the information. I am corrected it to data1 and now, it is working fine. one quick question, if my grid having lot of styles applied based on the data using cell template, will those also changed after refresh? – NewBuddy May 25 '16 at 12:49
  • Hi, I have a new problem now. I am adding columns via cell template that too dynamically using $scope.grid.columnDefs.push({}); When change filters and display the grid data, my grid is showing un wanted columns beside the original columns as blank columns. Can anybody tell me how to avoid this? – NewBuddy May 31 '16 at 09:32