Customised control buttons - if statement based on column value
Customised control buttons - if statement based on column value
Hello,
I am trying to implement some Customised control buttons but with a conditional statement.
Basically, the action of a button is dependant from the value of a column in the selected row.
My code is not totally wrong as:
* the else condition works fine, and
* if I remove the if condition, the action works fine
My problem is that the conditions do not work, probably because I am not testing properly the value of the colum of the selected row. (I get "Undefined" instead of the status that I am looking for)
Here is my code.
const iso20022_pain001_PmtInftable = $('#iso20022_pain001_PmtInf').DataTable( {
ajax: 'php/table.iso20022_pain001_PmtInf.php',
dom: 'Bfrtip',
buttons: [
{
extend: 'selectedSingle',
text: 'Valider',
action: function (e, dt, node, config) {
if (iso20022_pain001_PmtInfEditor.get('iso20022_pain001_PmtInf.statut') == 6) {
iso20022_pain001_PmtInfEditor
.edit(iso20022_pain001_PmtInftable.row({ selected: true }).index(), false)
.set('iso20022_pain001_PmtInf.statut', 7)
.submit();
}
else if ('iso20022_pain001_PmtInf.statut' == 7) {
iso20022_pain001_PmtInfEditor
.edit(iso20022_pain001_PmtInftable.row({ selected: true }).index(), false)
.set('iso20022_pain001_PmtInf.statut', 2)
.submit();
}
else alert( 'Ce paiement ne peut être validé' );
}
}
],
columns: [
{data: null, render: function ( data, type, row ) {
return data.iso20022_pain001_PmtInf.MsgId+ '-' +data.iso20022_pain001_PmtInf.PmtInf_id;
}},
{data: "iso20022_pain001_PmtInf.Dbtr_Name"},
{data: "iso20022_pain001_PmtInf.NbOfTxs"},
{data: "iso20022_pain001_PmtInf.ReqdExctnDt"},
{data: "statuts.statut"}
],
columnDefs: [
{
targets: 3,
render: DataTable.render.date()
}
],
order: [[ 0, 'asc' ]],
select: {
style: 'single'
}
} );
Would you know how I could amend rows 9 and 15 (I tested various options) to test the value of the 5th column?
This question has an accepted answers - jump to answer
Answers
You are trying to use the Editor's
get()
API in lines 9 and 15 but you haven't told the Editor what row of data to use. Instead use the Datatablesrow().data()
API. Something like this:Kevin
I know that
iso20022_pain001_PmtInfEditor.get('iso20022_pain001_PmtInf.statut')
can retrieve the data because as per the example, I can for example get the value and add 1 to it:But I don't manage to include it in the conditional statement. I tried that
Hi Kevin, I posted my last answer before seeing yours. Let me try it!
It worked like a charm, thanks Kevin!
I just have a NS_BINDING_ABORTED warning that I have to fix but getting close to what I am looking for.