update filter value without refreshing whole table
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}
/>
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.