Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling common function for cellClass Function in UI-Grid

I am intending to call same function for all columns. I tried many different way to call function. None did work. I am sure i did something silly. If someone can correct me.

$scope.gridOptions = {
enableSorting: true,
columnDefs: [
  { field: 'name', 
    //cellClass:  howCanIhaveCommonFunction() 
  },
  { field: 'company',
    //cellClass:  howCanIhaveCommonFunction()

  }
]

};

 // below function this would be common for all columns
  var howCanIhaveCommonFunction = function(grid, row, col, rowRenderIndex, colRenderIndex) 
  {
          if (grid.getCellValue(row,col) === 'Velity' || grid.getCellValue(row,col) === 'Beryl Rice' ) {
            return 'blue';
          }
          return 'red';
  }

http://plnkr.co/edit/4yjVbhmfR47cf7FGfyFk?p=preview

like image 849
Rajul Avatar asked Feb 13 '26 03:02

Rajul


1 Answers

Yes it is a simple mistake, instead of saying just the function name, you are invoking it without any arguments.

$scope.gridOptions = {
enableSorting: true,
columnDefs: [
  { field: 'name', 
    cellClass:  howCanIhaveCommonFunction 
  },
  { field: 'company',
    cellClass:  howCanIhaveCommonFunction

  }
]

You just made all the arguments null by having those (), just pass the function name and ui-grid will invoke it with right arguments.

like image 54
Kathir Avatar answered Feb 14 '26 16:02

Kathir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!