-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem mounting multiple instances of the spreadsheet on the same html page #3249
Comments
Hi, Could you provide some details on how to reproduce your bug? For instance your html structure and the javascript code used to instanciate the components? |
hi there, basically i am having to divisions in my html page where 2 different instances of the spreadsheet are mounted. basically i have 2 instances of a plain react component (think like a div with a ref attached to it), and inside each of these components i have this useEffect hook:
state management and canvas / sheet management seem not to be a problem in this case, but for the toolbar elements there are conflicts between the different instances of this component and so i am looking for a possible workaround |
Hi, Unfortunately, the menu registries are global and defined inside the library, which means that every mounted Spreadsheet will have to share the same top bar registry. Given the code you provided, you are adding children menu items to an isolated topbarMenuRegistry that will never be used because the library will always call If you want instance-related elements, you could rely on the visibility of the menu item and use custom conditions that would interact with your current React component to filter out the menus that you don't want to see. // import example giving you have injected the library in the browser
const { regitries } = window.o_spreadsheet;
const { topbarMenuRegistry } = registries;
// add this in your useEffect
// Adding a custom id for each react component. This will prevent collisions with other
// components as the id of the item is unique. This might be where you had some trouble
topbarMenuRegistry.addChild(`dashboard_${my_component_unique_id}`, ["file"], {.
name: _t("My button for spreadsheet 1"),
execute(env) { /*do stuff*/ },
isVisible: (env) => {
// add a dynamic condition that will be true if we are in right component, false otherwise
},
},
{ force: True } // in recent versions we prevent the automatic override of existing items
); It might also be interesting to clean up the menu registry if you were to spawn/unspawn lots of spreadsheets. Again, I apologize for the delay. I hope that you managed to find a workaround in the meantime. Have a great day |
i am having trouble using the toolbar buttons on an html page with multipl einstances of the owl spreadsheet component.
The sheet canvas and sheets navigation (so the Model) seems to work fine, but the toolbar buttons are added globally to only the first instance that gets mounted ...
is there a way to make toolbars also independent / instance-related elements
The text was updated successfully, but these errors were encountered: