Griddle icon indicating copy to clipboard operation
Griddle copied to clipboard

Cannot dynamically show or hide columns

Open jackgeek opened this issue 7 years ago • 11 comments

Griddle version

1.3.1

Expected Behavior

Changing the visible prop on ColumnDefinition should cause columns to be hidden or shown appropriately.

Actual Behavior

The column is only shown/hidden based on visible prop on first render. Subsequent updates don't get taken into consideration

Steps to reproduce

In render method:

    <Griddle
      data={data}
      plugins={[plugins.LocalPlugin]}
    >
      <RowDefinition>
        <ColumnDefinition id="name" title="Name" />
        <ColumnDefinition id="state" title="Location" order={1} width={400} />
        <ColumnDefinition id="company" title="Organization" visible={this.state.companyVisible} />
      </RowDefinition>
    </Griddle>

Now toggle this.state.companyVisible

jackgeek avatar Jun 08 '17 09:06 jackgeek

Just tried this on 1.6.0 and the same behaviour is experienced

jackgeek avatar Jun 08 '17 10:06 jackgeek

Try setting <Griddle key={...}> based on companyVisible, e.g.

<Griddle key={`visible:${this.state.companyVisible}`} data={data} ...>

dahlbyk avatar Jun 08 '17 21:06 dahlbyk

Yes thanks this works and is what I am presently doing. However there are potentially a lot of things I have to monitor the changes of and maintaining this is cumbersome. I have worked around this for now using key but it would be nice if the library responded to prop changes.

jackgeek avatar Jun 09 '17 09:06 jackgeek

Currently the row/column definitions are only parsed on initial load. I wonder if we should refresh them on componentWillReceiveProps?

dahlbyk avatar Jun 09 '17 13:06 dahlbyk

Sounds like a good idea to me

jackgeek avatar Jun 09 '17 16:06 jackgeek

The other thing I was thinking is that we could make the column definitions update the store for their own properties instead of Griddle top component managing the column settings (it just passes them to the store anyhow).

What I'm envisioning this looking like is the column definitions would also connect and have an action that fires off it's properties. Right now it's Griddle that does all that interaction. Thoughts? (I'm not opposed to any of the other routes either :D)

ryanlanciaux avatar Jun 15 '17 14:06 ryanlanciaux

@ryanlanciaux I'd be happy to take a shot at this. Your approach sounds like it might be the correct. Would you be able to point me in the right direction?

bpugh avatar Oct 17 '17 16:10 bpugh

Another thing to consider related to dynamic Row/Column definitions: I've run into a situation where it would have been nice to connect() a custom ColumnDefinition to an external store, specifically to load in a column visibility preference. I wasn't able to get it to work, though.

dahlbyk avatar Oct 17 '17 17:10 dahlbyk

Is it possible we have a solution to this issue yet? I'm working on implementing check boxes to all the columns and need to show/hide columns dynamically. Griddle only parses ColumnDefinition at the initialization.

ajpnaveen avatar Oct 21 '19 15:10 ajpnaveen

<Griddle
        storeKey="griddleStore"
        data={data}
        plugins={[plugins.LocalPlugin]}
        styleConfig={styleConfig}
        sortProperties={sortProperties}
        pageProperties={{
          currentPage: 1,
          pageSize: Number.MAX_SAFE_INTEGER,
        }}
        components={{
          Layout: newLayout,
        }}
      >
        {listingConfig && (
          <RowDefinition>
            {listingConfig.map((column, i) => {
              const { centerAligned } = this.props;
              return (
                <ColumnDefinition
                  id={column.id}
                  title={column.title}
                  key={column.id}
                  cssClassName={centerAligned && i !== 0 ? 'force-text-center' : ''}
                  headerCssClassName={`${
                    centerAligned && i !== 0 ? 'force-text-center' : ''
                  } ${column.headerClassName || ''}`}
                  customComponent={getFieldComponent(column)}
                  customHeadingComponent={column.customHeadingComponent}
                  sortMethod={column.sortMethod}
                  sortable={column.sortable !== undefined ? column.sortable : true}
                />
              );
            })}
          </RowDefinition>
        )}
      </Griddle>

In the following code, listingConfig is being read from the props. But when they change still the griddle table isn't updated. Any suggestions or fixes on the same?

anmol5varma avatar Jan 18 '22 11:01 anmol5varma

@anmol5varma I don't think any progress was made on a fix or work-around for this issue.

dahlbyk avatar Jan 18 '22 17:01 dahlbyk