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

Saving table column visibility state

Open djkingh01 opened this issue 6 years ago • 5 comments

Saving table column visibility state

Expected Behavior

Is there a way to save the state of the current user session like column visibility and filter criteria to the localStorage?

Current Behavior

Steps to Reproduce (for bugs)

Your Environment

Tech Version
Material-UI latest
MUI-datatables latest
React
browser
etc

djkingh01 avatar Mar 24 '19 20:03 djkingh01

Hi. I would like to start working on that issue. Could you please assign me for this?

marek-jarab avatar Oct 07 '19 18:10 marek-jarab

This sounds like something that is out of scope for this library to handle. The library exposes the ability to set all the initial states, from which you can recreate the state you wish, and save/restore however you wish. It's already possible with everything that exists.

E.g. (psuedocode)

// Seed initial state however you wish
constructor(props) {
  super(props);

  // array like ['true', 'false', 'true', 'false']
  savedDisplayColumns = localSotrage.get('displayColumns');

  this.state = {
    displayColumns: savedDisplayColumns 
  };
}

const columns = [
  { name: 'Name', options: { display: this.state.displayColumns[0] },
  ...
];

gabrielliwerant avatar Oct 08 '19 01:10 gabrielliwerant

You can also get some ideas from the serverside examples, just replace serverside requests with requests to something else, like local storage.

gabrielliwerant avatar Oct 08 '19 01:10 gabrielliwerant

Does #1718 satisfy this requirement?

jeje42 avatar Apr 29 '22 21:04 jeje42

Does #1718 satisfy this requirement?

In theory it should, but it does not appear to be working, at least for me on version 3.8.x. When I update visible columns it saves the column display property correctly to localstorage, but when I reload the page those column settings aren't retained.

On the other hand column order, for example, appears to properly be remembered across sessions.

I'm also noticing that the 'display' property on a column is also being stored as a string (i.e. "false") instead of a boolean type (although I don't think that matters).

image

x3igh7 avatar May 20 '22 14:05 x3igh7