API to add or disable a button

API to add or disable a button

whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
edited May 2013 in Editor
I was trying to disable, add, or remove buttons.


[code]
"oTableTools": {
"sRowSelect": "multi",

"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}

[/code]


I would like to be able to delete, add or hide the buttons but was unsure of what collection the belong to!

I was guessing
[code]
$(dataTable.oTableTools.('editor_create').update());
[/code]
or
[code]
$(editor.oTableTools.('editor_create').update());
[/code]

Thanks in advance.

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,050 Site admin
    Currently no - there isn't an API for enabling and disabling TableTools buttons I'm afraid. It is something that will be put into the next version of TableTools. Until then, what you could do is add a class to the button ('disabled') and have your fnClick function do nothing if it is disabled.

    Allan
  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
    Could I add the buttons on the fly?
  • allanallan Posts: 61,438Questions: 1Answers: 10,050 Site admin
    Currently no - there is no ability to add and remove buttons on-the-fly in TableTools.

    Allan
  • tpaulsmetpaulsme Posts: 4Questions: 0Answers: 0
    below the fnClick is overridden for two custom buttons to display an alert to the user and do nothing, with just a return:

    .... "oTableTools": {
    "sRowSelect": "single",
    "aButtons": [
    { "sExtends": "editor_create", "editor": editor, "sButtonText":"Add Specialty","fnClick":function(nButton, oConfig, oFlash){alert("You may not add specialties because thid doctor is not in your practice");return;} }},
    { "sExtends": "editor_remove", "editor": editor, "sButtonText":"Remove Specialty","fnClick":function(nButton, oConfig, oFlash){alert("You may not remove specialties because thid doctor is not in your practice");return;} }
    ]
    }
    } );


    If you are using PHP to control how you are putting the javascript into the page, you can controll it with a php var like this:

    //your conditions want it enabled.
    $dataTablesAddSpecialtyButtonDisabler = "";

    //your conditions want it disabled.
    $dataTablesAddSpecialtyButtonDisabler = ",\"fnClick\":function(nButton, oConfig, oFlash){alert(\"You may not add specialties because this doctor is not in your practice\");return;}";


    //then put this into where you define the two buttons in the javascript in php.
    { "sExtends": "editor_create", "editor": editor, "sButtonText":"Add Specialty"'.$dataTablesAddSpecialtyButtonDisabler.' },
    { "sExtends": "editor_remove", "editor": editor, "sButtonText":"Remove Specialty"'.$dataTablesRemoveSpecialtyButtonDisabler.' }
This discussion has been closed.