mui-datatables icon indicating copy to clipboard operation
mui-datatables copied to clipboard

Saving filter params, loading filter params on render?

Open andygock opened this issue 5 years ago • 3 comments

Hi,

What would be the best way to apply custom filter parameters immediately on the first render of a table?

For example, I'd like to save user selected filtering parameters in sessionStorage, so when a user returns to the table, the saved filter parameters (and possibly the page number) are loaded and applied again, otherwise the filter parameters are reset back to default.

Is there a way I could capture the filter parameters, and re-reapply them?

Andy

andygock avatar Oct 11 '19 11:10 andygock

Right now, you can designate the filters you want applied to any column with the filterList column option. You can do this dynamically if you want, and it should reset, reapply those filters; or when your component first mounts or something.

gabrielliwerant avatar Oct 12 '19 01:10 gabrielliwerant

Thanks @gabrielliwerant - that will work, using columns.filterList and options.onFilterChange should do what I need.

andygock avatar Oct 12 '19 08:10 andygock

I am doing the exact same thing but it does not seem to work for me. @andygock were you able to work it out.

I store the filterList in the session storage in onFilterChange. Then the user can navigate to some other page and come back to the page with the table. I defined the columns in a separate JS file (I have a lot of columns),

Here is my code snippet:

         const [columns, setColumns] = useState(null);
         const [data, setData] = useState(null);
         ..
         ..
         ..
          useEffect(()=>{
         // data is being read by a remote server 
           
             let table_columns = get_table_cols() // imported from another file (Array of objects)
             let sessionFilterList = get_filters_from_session()
             let columnDisplay = get_column_display_flag_from_session()
             for (let i = 0; i < table_columns.length; i++) {
                table_columns[i]['options']['display'] = columnDisplay[i] 
                table_columns[i]['options']['display'] = columnDisplay[i]  
              }
            setColumns(table_columns)
            setData(data)
          },[])

@gabrielliwerant Can you please help?

saching6 avatar Apr 11 '23 18:04 saching6