Toggle options like filtering and search
Hi, I have added an action to toggle the filtering option, but i cannot figure out a way to toggle this in the actual options object. It may be an obvious solution but i am new to react so any help is appreciated.
options={{ sorting: true, search: true, paging: true, pageSizeOptions: [5, 10 , 20], exportButton: true, filtering: showHideFilters }}
actions={[ { icon: Filter, tooltip: 'Toggle Filters', isFreeAction: true, onClick: (event) => alert(!showHideFilters) //has to be edited to update the bool value } ]}
Hi @KPpuria
Look at this example. It works.
class BasicFiltering extends React.Component {
constructor(props){
super(props);
this.state = {
filtering: true
}
}
render() {
return (
<MaterialTable
title="Basic Filtering Preview"
columns={[
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
},
]}
data={[
{ name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
{ name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
]}
options={{
filtering: this.state.filtering
}}
actions={[{
icon: "save",
onClick: () => this.setState({ filtering: !this.state.filtering }),
position: 'toolbar'
}]}
/>
)
}
}
I am closing this issue. You can reopen if it requires
thank you so much , this works
hi @mbrn and @KPpuria is it possible to do this for a column? i am trying to use an FreeAction to clear the default filter on a header column.
options={{
filtering: this.state.filtering
}}
thank you.