Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access entire row data in angular-ui-grid cellFilter

I would like to execute a cellFilter to programatically define what needs to be displayed within a cell. When defining the column definitions you need to specify what field the cell corresponds with, however I need access to the entire row of data within the cellFilter, not just a single field. Is it possible to pass multiple fields to a filter, or the entire row?

{
name: 'To',
field: 'myData',
cellFilter: 'formatCaller'
}

Thank you.

like image 697
user2589671 Avatar asked Feb 11 '23 15:02

user2589671


1 Answers

Yes, passing this as an argument to your filter sends the current scope

cellFilter: 'formatCaller:this`

Then in your filter you can access the row like so:

app.filter('formatCaller', function () {
  return function (value, scope) {
    return scope.row.entity.whateverField + ' ' + yourFormattingFunction(value);
  };
});

You can find a deeper explanation (and a plunker demo) here: http://brianhann.com/6-ways-to-take-control-of-how-your-ui-grid-data-is-displayed/ (caveat: I'm the author).

like image 54
c0bra Avatar answered Feb 13 '23 07:02

c0bra