Search code examples
cssreactjsag-gridag-grid-react

Adding styles to a specific header cell in AgGrid


I am working on AgGrid (AgGridReact component) with one of the header cells having a checkbox for 'select all'

Please refer the image here

Was wondering if there is a way to pad/margin the select-all checkbox in alignment with the checkboxes in the column.


Solution

  • You can add headerClass to a specific column definition and apply the css style as usual

    const columnDefs = [
      {
        checkboxSelection: true,
        headerCheckboxSelection: true,
        headerClass: "checkbox",
        width: 70
      },
      {
        headerName: "ID",
        field: "id",
        width: 70
      },
      ...
    }
    

    Css

    /* add role attribute to increase specificity */
    .ag-header-cell.checkbox[role="presentation"] {
      padding: 20px;
    }
    

    Live Demo

    Edit 64273758/adding-padding-margin-to-a-specific-header-cell-in-ag-grid