Griddle icon indicating copy to clipboard operation
Griddle copied to clipboard

How to setPage to 1 after event is fired.

Open DannyTakeuchi opened this issue 7 years ago • 6 comments

Griddle version

1.3.1

Expected Behavior

The table reverts back to page 1

Actual Behavior

The table stays on the same page as the previous search.

Steps to reproduce

  1. Add customized column filters that filters the data before it is imported into the table.
  2. Go to any page other than the first.
  3. Apply any column filter

DannyTakeuchi avatar Aug 08 '17 16:08 DannyTakeuchi

You can add a GRIDDLE_SET_FILTER reducer, via a plugin, that does a state.setIn(['pageProperties', 'currentPage'], 1).

I wonder if the default GRIDDLE_SET_FILTER reducer should mimic the local GRIDDLE_SET_FILTER reducer in resetting pageProperties.currentPage?

dahlbyk avatar Aug 09 '17 16:08 dahlbyk

I think that's a good idea. I think if a plugin doesn't want that behavior it could override that behavior but that would be the exception instead of defaulting to doing nothing.

ryanlanciaux avatar Aug 09 '17 18:08 ryanlanciaux

Opting out of a reducer is harder than opting in, AFAIK.

dahlbyk avatar Aug 09 '17 21:08 dahlbyk

Could you give an example of a custom reducer?

taylorshin avatar May 31 '18 00:05 taylorshin

@taylorshin12 you would define a plugin that includes:

const myPlugin = {
  reducer: {
    GRIDDLE_SET_FILTER: (state, action) =>
      state
        .set('filter', action.filter)
        .setIn(['pageProperties', 'currentPage'], 1),
  },
  // components, etc
}

This tells Griddle to replace the default behavior when an action with type: is dispatched.

It's not really documented, outside of tests, but you can also add before/after type handlers instead of replacing behavior:

const myPlugin = {
  reducer: {
    GRIDDLE_SET_FILTER_AFTER: (state, action) =>
      state
        .setIn(['pageProperties', 'currentPage'], 1),
  },
  // components, etc
}

Note our plugin now doesn't need to handle action.filter; it only resets the page number.

dahlbyk avatar May 31 '18 02:05 dahlbyk

Thanks for the help!

taylorshin avatar May 31 '18 02:05 taylorshin