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

update filter value without refreshing whole table

Open karanness86 opened this issue 6 years ago • 1 comments

Hello i am very new to react and started with react hooks. I have some understanding of useState and useEffect hooks but not in depth. I am trying to use the material table and filter feature to toggle change in filter status. I have code in place which allows me to toggle defaultFilter value. However toggling the defaultFilter reloads the data in table including if i have filtered on other values.

My end goal would be that end users would filter on certain values and then use the toggle button to show active/history rows. Maybe the way i am using useState is causing a rerender instead of just updating the value for the filter or maybe i am way off. I have tried some different approaches but all are causing the state to be refreshed.

Any help would be appreciate it.

function handleFiltert() { if(filter == "Active") { setFilter(null); setButtontext("Hide Historical Data") } else {setFilter('Active'); setButtontext("Show Historical Data")} //console.log(buttontext) } const [filter, setFilter] = useState("Active") const [buttontext, setButtontext] = useState("Show Historical Data") <button type="button" onClick={handleFiltert}> {buttontext} </button> <MaterialTable

    columns={[
        { title: "Row Status", field: "ROWSTS", readonly: "true", defaultFilter: filter, defaultSort: "asc"},
        { title: "Programcd", field: "Programcd", readonly: "true"},
        { title: "Program Type", field: "programty", readonly: "true"  },
                
      ]}
      data={rows}

/>

karanness86 avatar Dec 23 '19 18:12 karanness86

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Jun 20 '20 19:06 stale[bot]