Disable ajax button when no row are selected

Disable ajax button when no row are selected

ftaurinoftaurino Posts: 7Questions: 0Answers: 0
edited May 2012 in TableTools
hi all,

I've an ajax button used to do someting on selected rows, but when no row is selected, the action
is done on all the rows in the table. how can I disable the button when no row are selected?
like the "select_none" button...

many thanks,

francesco

Replies

  • ftaurinoftaurino Posts: 7Questions: 0Answers: 0
    no one with this requirement?
  • hozthozt Posts: 45Questions: 0Answers: 0
    You can go check if you have selected rows, using the API.
    Or just extend the select_none button, to do other actions, I guess, not sure if it would still keep his original function.

    But using the API works for sure.
  • ftaurinoftaurino Posts: 7Questions: 0Answers: 0
    fnGetSelected perhaps, but how?
  • ftaurinoftaurino Posts: 7Questions: 0Answers: 0
    partially solved with

    [code]
    "fnSelect": function( nButton, oConfig ) {
    if ( this.fnGetSelected().length !== 0 ) {
    $(nButton).removeClass('DTTT_disabled');
    } else {
    $(nButton).addClass('DTTT_disabled');
    }
    },
    "fnComplete": null,
    "fnInit": function( nButton, oConfig ) {
    $(nButton).addClass('DTTT_disabled');
    },
    [/code]

    but the button, even if with css class "DTTT_disabled", can be clicked and make the associated php script start....
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    The way to do it is to have your fnClick function check to see if rows are selected or not with fnGetSelected . Its is done like this so you could in theory pop up an alert that says "Error - no rows selected" - but most of the time you will just want to silently exit.

    Allan
  • ftaurinoftaurino Posts: 7Questions: 0Answers: 0
    edited May 2012
    solved with

    "fnClick": function ( nButton, oConfig, oFlash ) {
    if(confirm("Marcare come GESTITO e inviare i messaggi?")){
    var sData = this.fnGetTableData(oConfig);
    $.ajax( {
    "url": oConfig.sAjaxUrl,
    "data": [
    { "name": "tableData", "value": sData }
    ],
    "success": oConfig.fnAjaxComplete,
    "dataType": "json",
    "type": "POST",
    "cache": false,
    "error": function () {
    alert( "Errore durante aggiornamento!!! - ERR001" );
    }
    } );
    }
    },

    is there a way to _not_ include the "$.ajax" or make it simpler?
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    TableTools has a built in 'ajax' button, but it doesn't have the confirm option in it - so no - this is probably the best way of doing it at the moment.

    Allan
This discussion has been closed.