freedom freedom - 6 months ago 135
AngularJS Question

dynamic columnDef in ng-Grid

I want to assign ng-grid columns name dynamically after value returned from database, but issue is that it get initialized before data return from ajax, and i am not able to recall gridOption so it showing balnk, so please help me that how can we construct a column name by ajax return value.

$scope.gridOptions =
{
data: 'data.Values',
columnDefs:
[
{ field: "ID", displayName: "Record Id" },
{ field: "Value", displayName: $scope.ColumnName, cellFilter: cellfilterType },
],

};


where
$scope.ColumnName
coming from below line...

RecordService.getRecords().then(function (data) {
$scope.ColumnName= data.something;
}


Thanks

Answer

Thanks Max for your help, I have done this with of help columnDef as below

Step 1:

$scope.colDef = [];

Step 2:

RecordService.getRecords().then(function (data){      
    $scope.colDef=["CoulumnName":data.something]    
}

Step 3:

$scope.gridOptions = {   
    data: 'data.UdiValues',  
    columnDefs:'colDef',            
    filterOptions: $scope.filterOptions  
};