Newbie question: Datatables is loaded but options/settings not working

Newbie question: Datatables is loaded but options/settings not working

scotsscriptsscotsscripts Posts: 11Questions: 5Answers: 0
edited August 2017 in Free community support
<script type="text/javascript" class="init">
$('#article-table').DataTable( {
    ColumnDefs: 
    [
        { 
            targets: [ 6 ],
            orderData: 5   
        },
        {
            targets: [ 5 ],
            visible: false,
            searchable: false
        }
    ]
} );
</script>

Do you see any issues with the code above?

I'm trying to hide column 5 and sort column 6 based on column 5. Neither of which is working.

I've tried it with double quotes around the option words (the examples and docs show it both ways) but still no love.

Datatables is loaded and working; column sorting works and other options such as page length and whatnot work.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,948
    edited August 2017

    ColumnDefs:

    Should be:

    columnDefs:

    With a lower case c. The parameters are case sensitive.

    Kevin

  • scotsscriptsscotsscripts Posts: 11Questions: 5Answers: 0

    Thanks for responding. I changed it to columnDefs but no change in the behavior; the hidden column is still visible and it's still sorting on col 6 instead of 5. Any other ideas?

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    edited August 2017 Answer ✓

    To be clear, the first column is column 0, and so on

    Also, jquery scripts are typically put in jquery ready to make sure they don't fire off before the page is loaded so...

    <script type="text/javascript" class="init">
    $(document).ready(function(){
        $('#article-table').DataTable( {
            columnDefs: 
            [
                { 
                    targets: [ 6 ],
                    orderData: 5   
                },
                {
                    targets: [ 5 ],
                    visible: false,
                    searchable: false
                }
            ]
        } );
    });
    </script>
    
  • scotsscriptsscotsscripts Posts: 11Questions: 5Answers: 0

    Ah, that did the trick, thank you very much for taking the time to help, I appreciate it!

This discussion has been closed.