How to set cell style in ag-Grid while processing nodes?

泄露秘密 提交于 2019-12-12 22:22:34

问题


ag-Grid provides a mechanism using the cellStyle to modify the style of a cell.

However, I want to change the color of a cell while processing nodes. I know the exact node which I want to change the color of.

Is there some way to do that?


回答1:


The simplest solution would be to use a cell rendering function:

// put the value in bold
colDef.cellRenderer = function(params) {
    return '<b>' + params.value.toUpperCase() + '</b>';
}

You can apply the style depending on the value of the node - this will be made available in the params argument




回答2:


Use cellStyle or cellClass or cellClass in column property and return the

 var colDef = {name: 'Dynamic Styles', field' 'field2', cellStyle: cellStyling}

function cellStyling(params){
    if(true){
        return {'background-color':''};
    } else {
        return {'color': '#9B9999' ,'background-color':'#E8E2E1'};
    }
 }

as per your comment, code can be use like--

 $scope.gridOptions.api.forEachNode(function(node){
    for(var j=0;j<node.gridOptionsWrapper.columnController.allDisplayedColumns.length;j++){
    if(node.gridOptionsWrapper.columnController.allDisplayedColumns[j].colDef.headerName==="column Name"){
            node.gridOptionsWrapper.columnController.allDisplayedColumns[j].colDef.cellStyle = {apply style};
    }
  }
}


来源:https://stackoverflow.com/questions/41370574/how-to-set-cell-style-in-ag-grid-while-processing-nodes

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