Aroj Subedi
Aroj Subedi

Reputation: 51

Using Filter property of PrimeReact DataTable

One of the columns of the DataTable implemented is somewhat like this

{ field: 'FieldValuesAsText#XYZ', header: 'XYZ', width: '150px', sort: true, filterElement: 'No' }

<Column key={col.field} 
        field={col.field} 
        header={col.header}
        body={this.trimContent}
        filter={true}
        filterMatchMode="contains"
        sortable={col.sort}/>

The FieldValuesAsText is a object with XYZ as one of it's attribute. The custom function used in the body property successfully retrieves the value but the problem is when I try to do the filter operation. Since the filter defaults to field which in this case is FieldValuesAsText#XYZ, so it is obviously going to return undefined. How will I be able to make my filter properly work?

Upvotes: 0

Views: 6353

Answers (1)

Apostolos
Apostolos

Reputation: 10463

You need to implement a custom filter function. Here is a custom function that I have used to filter a similar column in my Datatable.

filterMatchMode="custom" filterFunction={customFunction}


export const customFunction = (value, filter) => {
  return value.toUpperCase().indexOf(filter.toUpperCase()) >= 0
}

Upvotes: 0

Related Questions