Forbiding action on buttons even on refresh table

Forbiding action on buttons even on refresh table

sdroulerssdroulers Posts: 43Questions: 14Answers: 0

Hi everyone,

I have nice working tables. On some occasion, the "close" event calls an Ajax request which is doing some heavy calculation on the server side.

I was looking for a way to disable changes (new / editing / remove) on my tables until this calculation is over.

Since I use some font-awesome buttons for actions on my tables, I started using some jQuery:

$('.editor_create, .editor_edit, .editor_create').prop('disabled', true)

which works almost fine on displayed buttons.

My issue is that if during the calculation process I update the displayed results of my tables (by using the search box for example) it will create new lines (and buttons) on which the preceding code will have no effect (logical).

I was wondering if there was any way in js to apply a class (or set a property) to newly appearing elements (a big listener?).

Maybe by your experiences you have some great ideas !

Many thanks,

Sébastien

This question has accepted answers - jump to:

Answers

  • Tester2017Tester2017 Posts: 143Questions: 22Answers: 17
    Answer ✓

    I am not sure, but maybe instead of setting the property disabled you could use .addClass('disabled') in the [postSubmit] event and .removeClass('disabled') in the [submitComplete] event.
    https://editor.datatables.net/reference/event/.

    This may help you maybe too: buttons.disable(); and buttons.enable();

  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0

    Well, thank you very much, it looks to me e very interesting idea.

    Since "new" buttons appear each time the table is filtered with new results (ie lines) I should perhaps attach those to some search event themselves related to some variable which indicate if a calculation process is going on.

    I was thinking of that because if I'm not wrong the submitComplete will fire even if my Ajax request is not over (asynchronous)

  • allanallan Posts: 52,525Questions: 1Answers: 8,020 Site admin
    Answer ✓

    I was thinking of that because if I'm not wrong the submitComplete will fire even if my Ajax request is not over (asynchronous)

    That shouldn't be the case. submitComplete should only be fired once Editor's Ajax request is complete and its done whatever processing it needs to based on the result.

    @Tester2017 is correct - buttons().enable() and buttons().disable() are the API methods needed to enable and disable buttons.

    Allan

  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0

    Thanks to both of you, I'll follow your wise advices.

    Great day,

    Sébastien

This discussion has been closed.