Button action

Button action

presse55presse55 Posts: 3Questions: 0Answers: 0

The names of several action functions for my buttons are stored in stables and available as a strings.
For example: we have button(5), the name of the action function for which is in a string which contains 'clickAdd()';
I wish to set the button action, at run time, using the function name 'provided as a string'.

First try:
var actionFuctionName = 'clickAdd()';
oTable.button(5).action( function ( e, dt, button, config) { actionFunctionName;});
The above does not work;

Second try:
oTable.button(idx).action( function ( e, dt, button, config) { eval(actionFunctionName);});
I have also tried the above, which does not work either.

However, in the console, the second try above does work, and the button behaves as required.

I have a sneaky suspicion the variable actionFunctionName is out of scope ... but, I'm not sure!

Appologies, as I am still relatively new to JS!

Thanks for hints and/or pointers to the appropriate datatables/JS documentation to do this!

Best regards from Montreal!

Replies

  • presse55presse55 Posts: 3Questions: 0Answers: 0

    Appologies - forum moderators feel free to move post to Buttons category, as that is where I had intended to post.

  • presse55presse55 Posts: 3Questions: 0Answers: 0

    I've looked more closely.
    My buttons do indeed get an action function attached.
    But ALL the buttons get the same function.

    So, the correction my procedure needs, is to ensure individual buttons each get the right function.

    Thankx again!

This discussion has been closed.