最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ng-grid cellTemplate doesn't work with CUSTOM_FILTERS included - Stack Overflow

programmeradmin6浏览0评论

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>"

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>"
Share Improve this question asked Sep 5, 2013 at 22:06 HiloHilo 8692 gold badges11 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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>"
发布评论

评论列表(0)

  1. 暂无评论