material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Toggle options like filtering and search

Open KPpuria opened this issue 7 years ago • 3 comments

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 } ]}

KPpuria avatar Nov 20 '19 13:11 KPpuria

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

mbrn avatar Nov 20 '19 18:11 mbrn

thank you so much , this works

KPpuria avatar Nov 21 '19 06:11 KPpuria

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.

karanness86 avatar Dec 20 '19 20:12 karanness86