So, I need to get 2 params from my dataTable, but from different columns, I render a button in one of those columns and post it data through a JS Function, but only that param is not enough, i really need another one, let me show you:
function table(){ // Define table id as a dataTable var table = $("#tabelaSintoma").DataTable( { "ajax": "webservices/ws_downtime/ws_tableSymptom.php",/* Ajax to pull all info about your table)*/ "columns": [ { "data": "sintoma"}, { "data": "CAUSA"}, { "data": "AREA"}, { "data": "COD" , render: function(data) {// that's the function i render the button, but I need to get the column above this... "data: AREA"... and then I have to POST it onclick. data = '<button type="button" class="btn btn-danger" onclick="callDisableCause(' + data + ');"><i class="fa fa-trash"></i></button>'; return data;} }, ] } ); }
I need to POST two params from different columns in the same functions, how can I do that?
And there is my function to POST to my php.
function callDisableCause(id){ var url = "webservices/ws_downtime/ws_disableCause.php" $.ajax({ method: "POST", url: url, data:{ id: id }, success: function(result){ swal({ title: "Cuidado!", // titulo do alerta text: "Deseja realmente desabilitar essa causa?", //texto apresentado ao cliente no alerta icon: "warning", // icone apresentado ('success', 'warning') buttons: true, // botoes(possivel personalizar, colocar o texto que melhor se encaixa na situação) }) .then((willDelete) => { // função para pegar o resultado do alerta if (willDelete) { // se for verdadeiro ele recarrega o formulario $('#mainpages').load('pages/downtime/downtime_admin/downtimeSymptom.php'); } else { // se for falso volta para a pagina principal $('#mainpages').load('pages/downtime/downtime_admin/downtimeSymptom.php'); } }); } }); }
Advertisement
Answer
The render function has three parameters. the third one has the data of the entire row. Try using this code
{ "data": "COD" , render: function(data, type, row ) { data = '<button type="button" class="btn btn-danger" onclick="callDisableCause(' + data + ', ' + row.COD + ');"><i class="fa fa-trash"></i></button>'; return data; } },
Regards!