2 columnDefs

2 columnDefs

CurtisKCurtisK Posts: 7Questions: 2Answers: 0
edited January 29 in Free community support

database columns: id, name, released, rating, link
php displays all columns with the link column (https://___)
In html I am doing this - <a href="link">name</a>
I have that working with the code below. Next I want to hide the id and link columns and found this code - "columnDefs" : [
//hide the first & fifthcolumn
{ "visible": false, "targets": [0,4] }
]
How can I add that code to the columnDefs below?
Or simply hide id and link column (since the URL is behind the name)

$(document).ready(function() {
    $('#mastertable').dataTable( 
    {    
        "order": [[2, 'desc']],
        "paging": true,
        "scrollCollapse": true,
        "scrollY": '80vh',
        "lengthMenu": [ [ 100, 250, 500, 1000, -1], [ 100, 250, 500, 1000, "All"] ], 
        "columnDefs": 
        [ 
            {   "targets": 1,"data": "download_link","render": function ( data, type, row, meta ) 
                {
                    return '<a href="'+row[4]+'">'+data+'</a>';
                }
            } 
        ]
    } )
} );

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    The columnDefs is an array of options, see the docs for examples. You combine the two, inside the array, with a comma separating them, like this:

            "columnDefs":
            [
                { "visible": false, "targets": [0,4] },
                {   "targets": 1,"data": "download_link","render": function ( data, type, row, meta )
                    {
                        return '<a href="'+row[4]+'">'+data+'</a>';
                    }
                }
            ]
    

    Kevin

Sign In or Register to comment.