Griddle
Griddle copied to clipboard
How to setPage to 1 after event is fired.
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
- Add customized column filters that filters the data before it is imported into the table.
- Go to any page other than the first.
- Apply any column filter
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
?
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.
Opting out of a reducer is harder than opting in, AFAIK.
Could you give an example of a custom reducer?
@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.
Thanks for the help!