How to check field value with custom button

How to check field value with custom button

GargiucnGargiucn Posts: 104Questions: 29Answers: 0

I created a custom editor button to check the value of a field before opening the editor.
I didn't understand the correct syntax to use to check the field.

        {
            extend: 'selectedSingle',
            text: 'selectedSingle',
            action: function (e, dt, node, config) {
                // if field value == value (for example: contratti.con_verif == 1)
                    alert("Pagamento verificato!");
                    this.close();
                }else{  
                    pagamentiEditor.edit(pagamentiTable.rows('.selected', { select: true }));
                }   
            }
        },

Giuseppe

Replies

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    The example:

    https://datatables.net/reference/button/selectedSingle

    shows:

     console.log( dt.row( { selected: true } ).data() );
    

    I tried with:

            {
                extend: 'selectedSingle',
                text: 'selectedSingle',
                action: function (e, dt, node, config) {
                    var verificato = dt.row( { selected: true } ).data();
                    if ( verificato[7] == 1 ){
                        alert("Pagamento verificato!");
                        this.close();
                    }else{  
                        pagamentiEditor.edit(pagamentiTable.rows('.selected', { select: true }));
                    }
                }
            },
    

    but it's wrong (undefined)...

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    I solved this way:

            {
                extend: 'selectedSingle',
                text: 'selectedSingle',
                action: function (e, dt, node, config) {
                    var verificato = (dt.rows( { selected: true } ).data().pluck('pagamenti').pluck('pag_verif')).join('');
                    if ( verificato == 1 ){
                        alert("Pagamento verificato!");
                        this.close();
                    }else{  
                        pagamentiEditor.edit(pagamentiTable.rows('.selected', { select: true }));
                    }
                }
            },
    

    I ask the experts for confirmation...

    Giuseppe

This discussion has been closed.