Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a cellRenderer function in ag-Grid return a React component?

I would like to use a cellRenderer in React for most of my columns. So, in my colDefs, I have an additional field called unit. If the unit exists, I am trying to have a heatMap like color grid which is handled in my TableCell React component. This identical react component has worked in other data grids like ZippyUI. Can the cellRenderer function return a React component, which is a virtual DOM object, or does it have to be a true HTML DOM object? Would doing something like this with ag-Grid's cellRenderer component method be preferable?

colDefs.map((x) => {
    if (x.hasOwnProperty('unit')) {
        x.cellRenderer = (params) => {
            return <TableCell value={params.value} units={x.unit} min={min[x.field]} max={max[x.field]} colorScheme={colorScheme} />;
        };
    }
});
like image 778
dsh Avatar asked Aug 28 '16 06:08

dsh


People also ask

How do you call a cellRenderer function in Ag grid?

when you pass the column definition to the ag-grid instance, it will have your function bound to cellrenderer attribute for that column. So when in its build lifecycle it checks the value at cellRenderer it will see your function and fire it then.

How do you make AG grid responsive in react JS?

The quickest way to achieve a responsive grid is to set the grid's containing div to a percentage. With this simple change the grid will automatically resize based on the div size and columns that can't fit in the viewport will simply be hidden and available to the right via the scrollbar.

What is agInit in Ag grid?

agInit() is called once (with the corresponding cell's parameters supplied). The component's GUI will be inserted into the grid 0 or 1 times (the component could get destroyed first, i.e. when scrolling quickly). refresh() is called 0...n times (i.e. it may never be called, or called multiple times).


1 Answers

For React, instead of using cellRenderer, cellEditor, etc, you want to use cellRendererFramework, cellEditorFramework and pass in a class that has setUp and render methods.

like image 163
Tom Avatar answered Sep 30 '22 02:09

Tom