Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sorting not working when using 'headerComponent' in ag-grid table

i needed to display custom header component for displaying icons and other thing in the colum-header and for that i've used 'headerComponent' in the column definition. But now the issue is that the sorting is not working with 'headerComponent'. Need help

Even sortable: true is not working. searched a lot about it online and in official docs of ag-grid but, haven't found any resolution.

{
    headerName: 'Content',
    field: 'content_count',
    headerComponent: () => {
        return (
            <AampeTooltip title="The total number of unique sendable message variants attached to this label.">
                <span>Content</span>
            </AampeTooltip>
        );
    },
    sortable: true,
    width: 96,
},
like image 834
vipin tiwari Avatar asked Apr 10 '26 12:04

vipin tiwari


1 Answers

If you are using the custom headerComponent, you need to implement all the functionalities yourself. See this example in the Doc, on how to implement custom sorting and filtering functions.

But if you would like to use the built in functionalities and add an inner custom component, then you can achieve it using headerComponentParams and innerHeaderComponent.

Example column definition:

{ 
  field: "height",
  headerComponentParams: {
    displayName: 'Column',
    innerHeaderComponent: MyHeaderComponent,
  }
}

And you can define your custom component:

const MyHeaderComponent = (params) => {
  const handleClick = () => {
    console.log('clicked...')
  }

  return (
    <div className="custom-div" onClick={handleClick}>
      {params.displayName}
    </div>
  );
}

Note that this inner component will be added inside the data-ref="eText" element.

See the example here.

You can also consider using Provided Components, if you want complete control over the generated html.

like image 78
Raghavendra N Avatar answered Apr 20 '26 15:04

Raghavendra N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!