如何访问angular-ui-grid cellFilter中的整行数据 [英] How to access entire row data in angular-ui-grid cellFilter
问题描述
我想执行一个 cellFilter 来以编程方式定义需要在单元格中显示的内容.在定义列定义时,您需要指定单元格对应的字段,但是我需要访问 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'
}
谢谢.
推荐答案
是的,将 this
作为参数传递给过滤器会发送当前作用域
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);
};
});
您可以在此处找到更深入的解释(和 plunker 演示):http://brianhann.com/6-ways-to-take-control-of-how-your-ui-grid-data-is-displayed/(警告:我是作者).
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).
这篇关于如何访问angular-ui-grid cellFilter中的整行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!