[DT 10] on init

[DT 10] on init

deliatordeliator Posts: 95Questions: 1Answers: 0

Hello,

I've trouble with extend buttons, part of my code below .
I need to hide the 2 buttons on table init.

(The select/deselect row click event is working)

Regards

Marc

            }).on('deselect', function(e, dt, type, indexes) {
                if(type === 'row') {
                    $('.btnAtt').hide();
                    $('.btnDes').hide();
                }
            }).on('select', function(e, dt, type, indexes) {
                if(type === 'row') {
                    var data = dt.row( { selected: true } ).data();
                    var id = (data[Object.keys(data)[2]]);
                    if( id.length === 0) {
                        $('.btnAtt').show();
                        $('.btnDes').hide();
                    }
                    else if(id.length != 0) {
                        $('.btnAtt').hide();
                        $('.btnDes').show();
                    }           
                }
            }).on('init', function() {
                $('.btnAtt').hide();
                $('.btnDes').hide();
            });     

Replies

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Hi Marc,

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    My guess is that you need to add the .dt namespace to your event listeners, but it isn't clear from the above code what the execution scope is there.

    Thanks,
    Allan

  • deliatordeliator Posts: 95Questions: 1Answers: 0

    Thanks Allan,

    Here is a working fiddle :smile:

    https://jsfiddle.net/fmneevea/1/

    So, my issue is that i want to hide the 2 buttons on init.

    Thanks

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Your table initialisation is synchronous. So the init event has already run by the time you attach the licenser for it. The init event is only useful if your table init is async (i.e. you Ajax load data).

    You could attach the event to the table before initialisation - or just run the code immediately afterwards: https://jsfiddle.net/fmneevea/3/ .

    Allan

This discussion has been closed.