how to add conditional template on ag-grid

寵の児 提交于 2019-12-11 04:23:08

问题


can I do a conditional template on the first column below?

for example: If my row has score property and I want to hide the input when my score is above 70?

let columns = [
            { width: 30, suppressSorting: true, suppressMenu: true, template: '<input type="checkbox">' },
            { headerName: "Score", filter: 'number', valueGetter: (params : any) =>
                params.data.traces ? (<Alert> params.data.traces[0]).severity : params.data.severity, width:70},
            { headerName: "Behaviour tags" },
            { headerName: "Host", field: "host_name" },
            { headerName: "Group Id", cellRenderer: 'group', width:140 },
            { headerName: "Comments",width:290 }
        ];

回答1:


Use cellRenderer property in your column object

let columns = [{ width: 30, suppressSorting: true, suppressMenu: true,
    cellRenderer: function (params) {
        var display = 'block';
        if (params.data.score > 70) {
            display = 'none';
        }

        var html = '<input type="checkbox" style="display: ' + display + '">';

        return html;
    }
}]

In params.data you have all row data



来源:https://stackoverflow.com/questions/39093485/how-to-add-conditional-template-on-ag-grid

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