Alter('remove_row') on custom Button deletes other Buttons eventListener

Hello,

Iam using alter(‘remove_row’) on custom Buttons and it working fine with:

$(‘.remove’).on(‘click’, function() {

                        hot1.alter("remove_row", hot1.getSelectedLast()[0]);
                    });

but when one Button is clicked the rest of the buttons doesnt react
Even tried with:

afterRemoveRow: function (index,amount)
                    {
                        $('.remove').off;

                        $('.remove').on('click', function() {
                            hot1.alter("remove_row", hot1.getSelectedLast()[0]);
                        });

                    }

But still alter(‘remove_row’) only works once

With

$('.remove').on('click', function() {
                             alert(.getSelectedLast()[0]);
                         });

alert shows several times with every button

Here is my colums config:

{
className : ‘remove-col’,
readOnly : true,
renderer : ‘html’

}

Hi @hercules

Can you share a demo where this issue can be replicable?

Hello aleksandra,

Well I did this: Edit fiddle - JSFiddle - Code Playground

Hope it helps but it doesnt remove a row in jsfiddle

However I also have implemented afterChange which has several functions even if there is no change this is called:

//If no changes or oldval===newval
if (!changes || changes[0][2] === changes[0][3]) {
return;
}

Is there maybe some overrides of listeners in the afterChange functionality?

I found the fix myself:

$(‘.remove’).on(‘click’,‘.remove’, function() {

                         alert(.getSelectedLast()[0]);
                     });

The problem was that there should be delegation in on() function in jquery and has nothing to do with handsontable

Sorry for keeping you waiting. I am glad that you’ve found the fix.

Thank you for an update.