Sampath Wijesinghe
Sampath Wijesinghe

Reputation: 690

Condition inside the datatabele

I created data table and in this, I want to check the condition, here is the part of my code:

buttons: [
                {
                    extend: 'pdfHtml5',
                    exportOptions: {
                    if(group_id != topManagementUserLevel){
                        columns: [0, 1, 2, 3, 4]
                          }
                    }
                },
            ],

I want to add if condition to check some values but when I am inserted that one into code Its gives an error.

Uncaught SyntaxError: Unexpected token !=

Is there a any other way to do this

Upvotes: 0

Views: 74

Answers (2)

random
random

Reputation: 7891

use ternary operator instead of if.

const group_id = 1;
const topManagementUserLevel = 2;

buttons = [
    {
        extend: 'pdfHtml5',
        exportOptions: {
            columns: (group_id != topManagementUserLevel) ? [0, 1, 2, 3, 4] : []
        }
    },
];

console.log(buttons);

Upvotes: 1

Asim Khan
Asim Khan

Reputation: 2039

You can use this conditional statement.

columns: (group_id != topManagementUserLevel) ? [0, 1, 2, 3, 4] : undefined

Upvotes: 1

Related Questions