create if statement with datatables
create if statement with datatables
Imam Trizna
Posts: 5Questions: 1Answers: 0
could someone help me to fix my code
i want to show the data from database with if conditions
{ "data": "Jabatan" },
{ data: 'Kode',
render: function ( data, type, row, meta ) {
if (data == '83') {
return { "data": "Nama" },
}
else if (data != '83') {
return { "data": "kelas" },
},
},
},
but its not work, can anyone help me to fix this...
This discussion has been closed.
Answers
Hi @Imam Trizna ,
You don't return
{ "data": "Nama" }
, you return"Nama"
.So something like:
Cheers,
Colin
@colin
thanks for your reply
i have tested but return "Nama"; will show text nama, but i need show the value of data nama on my database..
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Try
return data.nama
@colin
sorry
this is my full code
var table = $('#data').DataTable( {
"ajax": "ajax-grid-data.php",
"order": [[ 0, 'asc' ]],
"columns": [
{ "data": "Nama" },
{ "data": "Pangkat" },
{ "data": "Kelas" },
{ "data": "Jabatan" },
{ data: 'Kode_Pangkat',
render: function ( data, type, row, meta ) {
if (data == '83') {
return "Nama";
} else if (data != '83') {
return "Pangkat";}
},
},
],
} );
i neet show return to my columns { "data": "Nama" }, value on if condition like that
@colin
Try return data.nama
it stil not work, it show requested unknown parameter
Yep, it looks like you've capitalised it - so it'll be "data.Nama". If that doesn't work, please supply a test case, instructions are above.