Color the background of a cell in ng-grid with rgb value in data

久未见 提交于 2019-12-13 21:01:11

问题


I am using ng-grid and I have a database that contains a column with rgb values such as #fc3b25, etc. I need to set the background color of each cell in the rgb column to the value contained in the database. In the libraryGrid, I have defined the columnDes as follows:

{
    field: 'rgb',
    displayName: 'Key',
    width: '50px',
    cellTemplate: "<div style='height:60px; width:50px; background-color: {{ row.getProperty('rgb') }} ;' >rgb</div>"
}

This does not work. It seems that a directive might be appropriate here, but I haven't had any success there either. Any suggestions?


回答1:


Write your celltemplate like this:

{field:'rgb', displayName:'Age', cellTemplate: '<div style="background-color:{{row.entity.rgb}}" ><div class="ngCellText">{{row.getProperty(col.field)}}</div></div>'}]

Look here for a working Plunker



来源:https://stackoverflow.com/questions/23013985/color-the-background-of-a-cell-in-ng-grid-with-rgb-value-in-data

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