Custom FilterCell on some GridColumns without creating individual GridColumn

1 Answer 49 Views
Filter  Grid
smd
Top achievements
Rank 1
Iron
Iron
smd asked on 08 Nov 2024, 03:59 AM | edited on 08 Nov 2024, 05:41 PM

Hi,

So, I realized that if I create a <Grid data={dataSource}></Grid>, without anything in between, it is smart enough to create all the columns for me. That is super awesome, since I have a dataset with 16 columns.

However, now that I need to customize the filterCell for a couple particular columns. How do I do that? I have two solutions

1/ It seems like if I create one GridColumn (to have filterCell attribute), I have to create all 16 of them.

2/ I can do a mapping function to create all the non-customized columns, but since the customized ones are not in sequential order, all the columns excluded from the mapping function will be placed at the end (right-most of the grid) - which is not ideal. 

Any help is greatly appreciated.

Best regards,

Luu

1 Answer, 1 is accepted

Sort by
1
Accepted
Yanko
Telerik team
answered on 11 Nov 2024, 12:52 PM

Hello,

In this scenario, you can use the `filterCellRender` property of the Grid to render the filter cells only for the desired fields, you can acquire the default filter cells through `row.props.children.props.children[0]`, or you can provide custom ones if needed:

filterCellRender={(row, props) => {
        if (props.field == 'ProductName' || props.field == 'Discontinued')
          return (
            <div className="k-filtercell">
              {row.props.children.props.children[0]}
            </div>
          );
        else
            return <React.Fragment/>;
      }}

I prepared a StackBlitz example that shows how to apply the above approach on a Grid that has automatically defined columns:

Regards,
Yanko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Filter  Grid
Asked by
smd
Top achievements
Rank 1
Iron
Iron
Answers by
Yanko
Telerik team
Share this question
or