2
votes

I am trying to get a cell in my row/column grid to display as an empty cell or blank content given a certain case and as a CellRenderer type in another case. Currently I am doing:

cellRendererSelector: function (params) {
  const exampleCheckBox = {
    component: 'exampleCheckboxCellRenderer',
    params: {values: ['true', 'false']}
  };

  if (params.data.exampleField) {
    return exampleCheckBox;
  } else {
    return null; // HERE: null sets the string value of that field as a default cell
  }
},

In my else case above I want to return or show an empty cell or a cell with an empty string. Returning null only returns a default basic cell with the field value as a string.

1

1 Answers

0
votes

The cellRendererSelector is a function that returns the name of the component to be used as a renderer, or null.

You could try either of these two approaches:

  1. Creating a Cell Renderer that returns an empty string, e.g. exampleEmptyRenderer:

    if (params.data.exampleField) {
                return exampleCheckBox;
            } else {
                return exampleEmptyRenderer; 
            }
    
  2. Inside the exampleCheckBox renderer, add logic to do the checking inside the init method to conditionally return what you want, as you have access to the node data:

ExampleCheckBoxCellRenderer.prototype.init = function (params) {
    this.eGui = document.createElement('div');

    if (params.data.exampleField) {
    // here return your renderer
        this.eGui.innerHTML = params.value;
    } else {
    // here return empty string
        this.eGui.innerHTML = ''
    }
}