Sumit Sharma
Sumit Sharma

Reputation: 126

How to hide a cell value based on another cell value in datatable

I am working in a like below

var table = $('#tblPay').DataTable({
            "ajax": $("#DefaultGridUrl").val() + '/?application=' + application,
            "destroy": "true",
            'columnDefs': [{
                'targets': 3,
                'searchable': false,
                'orderable': false,
                'render': function (data, type, full, meta) {
                    return '<a class="downloadFile" href="#" data-uri=' + uri + ' data-application=' + application + ' data-id="' + data + '"></a>';
                }
            }],
            'language': {
                "emptyTable": "Nothing found."
            },
            "columns": [
                { "data": "Name" },
                { "data": "Size" },
                { "data": "LastUpdate" },
                { "data": "Name" }
            ]
        });

Now I want that if size comes 0 for a row then I need to hide download which is in render section (last column). I tried passing array from targets and use that but I think I am doing something wrong.

Upvotes: 0

Views: 572

Answers (1)

Yevhen Horbunkov
Yevhen Horbunkov

Reputation: 15550

If the cell with column index 3 (where you render your link into) should be left empty for rows, having size==0, you can simply modify your render function to something, like:

'render': (data, type, full, meta) => 
    full.size != 0 ? `<a class="downloadFile" href="#" data-uri="${uri}" data-application="${application}" data-id="${data}"></a>` : '';

Upvotes: 1

Related Questions