angular-ui-grid中的自定义数据过滤器

时间:2017-08-08 12:16:27

标签: angular angular-ui angular-ui-grid

{
    "grossValue": 500,
    "items": [
        {
            "billNo": "3",
            "name": "coke",
            "id": 556,
            "billAmount": 150,
            "quantity": 1,
            "ingredientType": {
                "isNonVeg": false,
                "isAlcoholic": false,
                "isBeverage": false
            }
        },
        {
            "billNo": "4",
            "name": "hot dogs",
            "id": 586,
            "billAmount": 247,
            "quantity": 1,
            "ingredientType": {
                "isNonVeg": false,
                "isAlcoholic": false,
                "isBeverage": false
            }
        }
    ]
}

我有JSON来自请求URL的数据库 我想在最后一个显示ingredientType的列中显示一个列 如果在最后一列的单元格中所有Boolean值都为false,则显示“veg”。

问题是我无法将函数的值绑定到columnDefs数组中的特定列的单元格,

columnDefs: [
    {field: 'billNo'},
    {field: 'name'},
    {field: 'id'},
    {field: 'billAmount'},
    {field: 'quantity'},
    {field: 'ingredientType'}
]

1 个答案:

答案 0 :(得分:0)

认为这就是你想要的。此基本示例将该行记录到控制台输出。

$scope.myFunction = function(rowEntity) {
    console.log('$scope.myFunction called', rowEntity);
}

var actionTemplate = '<button ng-click="grid.appScope.myFunction(row.entity)">MyFunction</button>';

columnDefs: [
    {field: 'billNo'},
    {field: 'name'},
    {field: 'id'},
    {field: 'billAmount'},
    {field: 'quantity'},
    {field: 'ingredientType'},
    {
      field: 'actions',
      displayName: 'Actions',
      cellTemplate: actionTemplate
    }
]