Sheet contextMenu disapear after sheet update

Community Driven Extensions Project
Post Reply
bug007
Posts: 39
Joined: 07 Oct 2015, 12:08

26 Jul 2018, 12:38

Hi,
version 6.2.7
I would like to try use contextMenu like showcase, this work fine on the fisrt load, but when I update data on the sheet, contextMenu is be lost !
How can I create it and always stay ? It should be great to don't have to recreated at each refresh ?
Thanks for your help

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

26 Jul 2018, 13:27

I think there is 1 of 2 ways to solve it.

1. Put in in a JS function and call it after your Ajax Update like...

Code: Select all

<p:ajax update="mySheet" oncomplete="addContextMenuJs();" />
2. Instead of using $hot.updateSettings doing it in the Sheet Extender funciton. The Extender should get called on every update of the sheet when it re-initializes.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

26 Jul 2018, 13:59

Now that I think about it you may have to use Solution #1 because in #2 the sheet doesn't exist yet the Extender is before the sheet is created so there is no way to get at the $hot value.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

bug007
Posts: 39
Joined: 07 Oct 2015, 12:08

26 Jul 2018, 15:13

Thanks Melloware, it's exact, on the extender I can only use standard declaration like :

Code: Select all

this.cfg.contextMenu = ['row_above', 'row_below', '---------', 'undo', 'redo']; 
but not your.

Than I've implemented the 1 solution.
For your information, I saw an error with contextMenu if the sheet is empty.

Now, I look the better way for insert (after or before) a "Template" line with default value by backing bean to integrate it on the same time into the database table .... Any experience ?

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

26 Jul 2018, 15:35

Yeah the context menu you might have to get smarter with the JS code. I grabbed their example almost exactly from the HandsonTable docs...

https://docs.handsontable.com/5.0.0/dem ... -menu.html
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

bug007
Posts: 39
Joined: 07 Oct 2015, 12:08

21 Aug 2018, 18:17

Hi, with the solution to add contxet menu after each change, I found a handsontable issue => event hooks calling more time than once !
Similar problem of https://github.com/handsontable/handson ... ssues/3343

Than I look how is it posssible to re add context menu and also hook.
Here my patch exemple solution for remove row :

Code: Select all

$(document).ready(function () {
                            addContextMenu();
                        });

                        function addContextMenu() {
                            var $hot = PF('listSheet').ht;
                            $hot.removeHook('afterRemoveRow', cbRemoveRow); // this is very important !
                            $hot.updateSettings({
                                contextMenu: {                                    
                                 items: {
                                        "remove_row": {
                                            name: 'Delete line(s)',
                                            disabled: function () {
                                                // if first row, disable this option
                                                try {
                                                    return $hot.getSelected()[0] === 0;
                                                } catch (error) {
                                                    return true;
                                                } 
                                            }
                                       }
                                }
                            });
                            $hot.addHook('afterRemoveRow', cbRemoveRow);
                        }
                        ;
                        
                        function cbRemoveRow (index, amount){
                                deleteRows([{name: 'index', value: index}, {name: 'amount', value: amount}]);
                            };
Hope this can help someone !

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

21 Aug 2018, 19:10

Excellent!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: StevenPrab and 4 guests