active button
active button
Andreas S.
Posts: 208Questions: 74Answers: 4
in Buttons
I have a problem to activate a button if no row is selected and deactivate if a row is selected.
I tried with this code:
dtButtons.push( {
text: '<i class="fas fa-check-double fa-fw"></i>',
titleAttr: button_txt[3],
className: 'text-Peru',
action: function( e, dt, node, config ) {
var data = mt_sum.row( { deselected: true } ).data();
$.post( {
url: 'lib/adm/meet-api.php?mmap=7'
} )
.done( function( data ) {
var notify = ( undefined == data.title ) ? JSON.parse( data ) : data;
if( 'done' != notify.type ) {
pNotify( notify.title, notify.text, notify.icon, notify.type );
}
mt_sum.ajax.reload();
});
},
enabled: true
} );
mt_sum.on(
'select', function () {
var selectedRows = mt_sum.rows( { selected: true } ).count();
if( 6 == uLevel || 5 == uLevel ) {
mt_sum.button( 3 ).enable( selectedRows === 1 );
mt_sum.button( 4 ).enable( selectedRows === 1 );
} else if ( 4 == uLevel ) {
mt_sum.button( 3 ).enable( selectedRows === 1 );
mt_sum.button( 4 ).enable( selectedRows === 1 );
}
} );
mt_sum.on(
'deselect', function() {
var selectedRows = mt_sum.rows( { selected: true } ).count();
if( 6 == uLevel || 5 == uLevel ) {
mt_sum.button( 3 ).disable( selectedRows === 0 );
mt_sum.button( 4 ).disable( selectedRows === 0 );
} else if( 4 == uLevel ) {
mt_sum.button( 3 ).disable( selectedRows === 0 );
mt_sum.button( 4 ).disable( selectedRows === 0 );
}
} );
Have anyone a hint for me.
Andreas
This question has accepted answers - jump to:
This discussion has been closed.
Answers
What is
uLevel
? Maybe you can useconsole.log(uLevel);
in your functions to make sure it is what you expect. Could be that none of the if statements are true causing theenable()
anddisable()
statements to not be executed.Looks like if a row is selected you are enabling the button:
enable( selectedRows === 1 )
and disabling the button if 0 rows are selected:disable( selectedRows === 0 )
. This sounds opposite of your description above.Also you might need to change the statements to look like this:
``enable( selectedRows === 1 ? true : false );`
To specifically return
true
orfalse
.I do this with one of my buttons based on row selection:
If one or more rows are selected the button is enabled or disabled if no rows ar selected. Doing it this way seems like a simpler more readable code. You would just have to add your logic for the
uLevel
.HTH,
Kevin
I'd go a step further even than Kevin's excellent answer:
That uses
buttons().enable()
to manipulate multiple buttons at a time.Allan
Thanks, for help to solve my Problem. Sometime I did not see the tree in the forest.
Andreas