Formatting table with a few options

Formatting table with a few options

Dane JurkovicDane Jurkovic Posts: 12Questions: 6Answers: 0

Hello and thank you to anyone that helps me with this problem...

So I am trying to format my table using the following code. What i am trying to do is a "few" things...

1) make the table responsive.
2) make the default order on the second column (there are seven columns within the table).
3) make is so they can't search or order on the first column.
4) hide the last column from "view" but still visible when viewing page source.

$(document).ready(function () {
    var table = $('#myTable').DataTable({
        responsive: true,
        order: [1, 'asc'],
        columnDefs:
        [
            { searchable: false, orderable: false, targets: [0] }, 
            { visible: false, targets: [6] }
        ]
    });
}); 

I can get everything to work with the above code but not hiding the last column.

Again thanks for any help you can provide...

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,353Questions: 26Answers: 4,955

    Looks like your code should work. Do you have 7 columns in your table?

    targets: [6] would be column 7. You can also use targets: -1 for the last column.

    Can you post a link to your page for debugging?

    Kevin

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    Hi, tried your code with one of my tables. I had no problem with hiding the respective column. It worked fine.

    Maybe your table doesn't have 7 columns but only 6? In that case the last column won't get hidden with this ...

  • Dane JurkovicDane Jurkovic Posts: 12Questions: 6Answers: 0

    There are 7 columns in the table. The webpage is on our intranet so it is not outward facing.

  • Dane JurkovicDane Jurkovic Posts: 12Questions: 6Answers: 0

    Just removed line 3.... responsive: true,
    and everything works but now the table is not responsive.
    anyone know why?

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    I tested it with a responsive table as well - and it worked. Strange.

    I don't believe it could make a difference but I put the responsive thing into the default section like this. It is not in any of my table definitions. But again that shouldn't make any difference ...

    //Data tables default settings
        $.extend( true, $.fn.dataTable.defaults, {
            fixedHeader: {
                header: true,
                headerOffset: $('.navbar-header').outerHeight()
            },
            paging: true,
            colReorder: true,
            responsive: true,
            select: true
        } );
    
  • kthorngrenkthorngren Posts: 21,353Questions: 26Answers: 4,955
    Answer ✓

    I would check for errors in your browser's console. Make sure you are running a current version of responsive. I took your code and copied it here:
    http://live.datatables.net/qihituxi/1/edit

    All I changed was the target since the example table has only 6 columns. Maybe there is something else in your code that is affecting the display. Can you update the above example to replicate your issue?

    Kevin

  • Dane JurkovicDane Jurkovic Posts: 12Questions: 6Answers: 0

    Thanks for all your help. I downloaded the newer version of responsive and everything works as needed.

    Thanks again....

This discussion has been closed.