Formatting table with a few options (version 2)

Formatting table with a few options (version 2)

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

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

I thought I had this solved but I guess I missed on one important part.. I was able to hide the 7th column like I wanted to but by doing it the way I did (see code below) I also hid it from being seen when I want to "view page source".

anyone knows how to hide a column but still have it visible to be viewed when using "view page source".

Again thanks for any help you can provide...

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

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    That should work. If you "View source" on this page you'll see all six columns in the HTML.

    Make sure you "View source" and not "Inspect"!

    Allan

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

    Your right it does show. But I can't get the value from the hidden column. Why?

    $("#myTable").on('click', '.btnSelect', function () {
        var currentRow = $(this).closest("tr");
        alert('Manager: ' + currentRow.find("td:eq(6)").text());
    });
    
  • kthorngrenkthorngren Posts: 20,140Questions: 26Answers: 4,735
    Answer ✓

    I think you would be better off using Datatables API's for this. For example:

    $("#myTable").on('click', '.btnSelect', function () {
        var currentRow = table.row($(this).closest("tr")).data();
        alert('Manager: ' + currentRow[6]);
    });
    

    Kevin

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

    Thanks kthorngren! It works!

This discussion has been closed.