Replies: 4 comments 3 replies
-
So I made some progress with this, by creating a FilterWrapper which can provide the instance as context: import { useState, createContext, useContext } from "react";
export const FilterContext = createContext();
export const FilterWrapper = ({ children }) => {
const [instance, setInstance] = useState();
return (
<FilterContext.Provider
value={{
instance,
setInstance,
}}
>
{children}
</FilterContext.Provider>
);
};
export const useFilterState = () => {
return useContext(FilterContext);
}; I can now actually render the filter fields of each column anywhere on the page I like. Filtering of the table will then actually work, but the filter fields themselves don't actually update yet to show the current filter value. That's next thing I'll be working on. Is this most efficient, best-practice solution? Most definitely not, so if anybody has any suggestions on a different/better approach please let me know! :) |
Beta Was this translation helpful? Give feedback.
-
Hey did you make any progress with this? I can easily move the global filter outside the table but not the column specific filters. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
This can be used for filterValue update in the filter UI. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I don't need a full worked-out solution, just a push in the right direction.
Table.jsx
FilterModule.jsx
What would be the approach to move the FilterModule outside of the Table component? Eventually I want to place it inside a sidebar, a component far away in the React tree.
Would I need to make a context? Any suggested resources to read? What's best practice here?
Thanks! :)
Beta Was this translation helpful? Give feedback.
All reactions