Skip to content

How to add a custom dropdown filter? #4133

Answered by pellea
pellea asked this question in Q&A
Discussion options

You must be logged in to vote

I found the answer thanks to other questions ...

For a ColumnDef :

      {
        header: 'Status',
        accessorFn: x => x.fullObj,
        cell: info => (
          <CustomCompTag />
        ),
        filterFn: selectFilterFn,
        meta: {
          filterComponent: CustomFilter
        }
      },

with selectFilterFn as:

const selectFilterFn : FilterFn<any> = (row, columnId, value, addMeta) => {
  if (value === undefined || value.length === 0) {
    return false;
  } else {
    const { someProp, otherProp } = mapOrConvertBackLabel(value);
    return someProp.includes(row.original.myObj?.someProp) && otherProp .includes(row.original.myObj?.otherProp );
  }
};

and with CustomFilter

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@kmer75
Comment options

@Samettkaya
Comment options

@zzincist
Comment options

Answer selected by pellea
Comment options

You must be logged in to vote
2 replies
@Samettkaya
Comment options

@legion40216
Comment options

Comment options

You must be logged in to vote
1 reply
@zzincist
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants