Setting value via button

Setting value via button

milapmilap Posts: 40Questions: 13Answers: 2
edited July 2021 in Buttons

Hi,
I am trying to build a super simple custom button that should insert a value 1 to a database bool column 'active'
But it is not working...

Here is my code:

var editor = new $.fn.dataTable.Editor( {
...
});

new $.fn.dataTable.Buttons( table, [
{
    text: 'Activate',
    action: function ( e, dt, node, config ) {
        editor.field( 'active').set( 1 );
        editor.submit();
        //Shall I reload the table after?
        //table.ajax.reload( null, false );
    },
    enabled: false
}
] );

The problem is that there are no errors in browser console so I am not able to debug the problem.
I assume then that something is wrong with submit it self (there is also no JSON data passed while clicking button in Chrome dev-tools Network tab - no request at all)
All fields & db columns names are properly set...
Any idea what I have made wrong?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    I'm not clear where that code would be called. If it's on a button on the main table, then you would need to go into edit() first to start the edit. Can you give more context, please, or link to your page so we can see this in action,

    Colin

  • milapmilap Posts: 40Questions: 13Answers: 2

    Thank You Colin for a tip, You are right with edit().

    I have modified my button to code below and now it is working

    {
                extend: "selected",
                text: 'Activate',
                action: function ( e, dt, node, config ) {
                    editor
                        .edit( table.rows( { selected: true } ).indexes(), false )
                        .set( 'active', '1' )
                        .submit();          
                },
                enabled: false
    }
    
Sign In or Register to comment.