ng-grid cellTemplate doesn't work with CUSTOM_FILTERS included

浪尽此生 提交于 2020-01-14 12:54:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!