create if statement with datatables

create if statement with datatables

Imam TriznaImam Trizna Posts: 5Questions: 1Answers: 0
edited February 12 in Free community support

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...

Answers

  • colincolin Posts: 4,668Questions: 0Answers: 817
    edited February 12

    Hi @Imam Trizna ,

    You don't return { "data": "Nama" }, you return "Nama".

    So something like:

                        if (data == '83') {
                               return "Nama";
                        }
    
                        return "kelas";
    

    Cheers,

    Colin

  • Imam TriznaImam Trizna Posts: 5Questions: 1Answers: 0

    @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..

  • colincolin Posts: 4,668Questions: 0Answers: 817

    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

  • colincolin Posts: 4,668Questions: 0Answers: 817

    Try return data.nama

  • Imam TriznaImam Trizna Posts: 5Questions: 1Answers: 0
    edited February 12

    @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

  • Imam TriznaImam Trizna Posts: 5Questions: 1Answers: 0

    @colin

    Try return data.nama

    it stil not work, it show requested unknown parameter

  • colincolin Posts: 4,668Questions: 0Answers: 817

    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.

Sign In or Register to comment.