【问题标题】:Ag-grid how to update a specific cell style after clickAg-grid单击后如何更新特定的单元格样式
【发布时间】:2019-12-26 10:43:11
【问题描述】:

我使用refreshCells 在单击后更新特定的单元格样式。但是,这不起作用,当我设置refreshCells({ force: true }) 时,整个列都会更新我不想要的新样式。请问有什么建议吗?

    vm.gridOptions = {
        columnDefs: vm.columnDefs,
        rowData: vm.rows,
        angularCompileRows: true,
        defaultColDef: {
            sortable: true,
            resizable: true,
        },
        onCellClicked: onCellClicked,
        onGridReady: function (params) {

        }
    }

    function onCellClicked(params) {
        const focusedCell =  params.api.getFocusedCell();
        focusedCell.column.colDef.cellStyle = { 'background-color': '#b7e4ff' };
        params.api.refreshCells({
            force: true // this updates the whole column, not only the clicked cell
        });
    }

【问题讨论】:

    标签: angularjs ag-grid


    【解决方案1】:

    我通过设置特定的rowNodescolumns 解决了这个问题。

        function onCellClicked(params) {
            const focusedCell =  params.api.getFocusedCell();
            const rowNode = params.api.getRowNode(focusedCell.rowIndex);
            const column = focusedCell.column.colDef.field;
            focusedCell.column.colDef.cellStyle = { 'background-color': '#b7e4ff' };
            params.api.refreshCells({
                force: true,
                columns: [column],
                rowNodes: [rowNode]
            });
        }
    

    【讨论】:

      猜你喜欢
      • 2021-07-16
      • 2020-06-15
      • 2022-12-03
      • 1970-01-01
      • 2021-07-18
      • 2023-03-18
      • 2020-10-07
      • 2020-04-05
      • 1970-01-01
      相关资源
      最近更新 更多