问题
When including a cellTemplate in a column definition, if that cellTemplate includes CUSTOM_FILTERS, it causes angular to puke:
Error: Syntax Error: Token 'CUSTOM_FILTERS' is an unexpected token at column 14 of the expression [row.entity.1 CUSTOM_FILTERS] starting at [CUSTOM_FILTERS]
Even using the default cellTemplate in a column def results in the same error.
cellTemplate = "<div class=\"ngCellText\" ng-class=\"col.colIndex()\"><span ng-cell-text>{{COL_FIELD CUSTOM_FILTERS}}</span></div>"
回答1:
It turns out the ng-grid code assumes you have hard coded your custom filter into your specified cellTemplate:
self.cellTemplate = colDef.cellTemplate || $templateCache.get('cellTemplate.html').replace(CUSTOM_FILTERS, self.cellFilter ? "|" + self.cellFilter : "");
As you can see, they don't do a replace if you have specified a cellTemplate in you column def. So if you are providing a custom cellTemplate for a column and would like a cellFilter, you would do something like this:
cellTemplate = "<div class=\"ngCellText\" ng-class=\"col.colIndex()\"><span ng-cell-text>{{COL_FIELD |number:3}}</span></div>"
来源:https://stackoverflow.com/questions/18646724/ng-grid-celltemplate-doesnt-work-with-custom-filters-included