Hidding a column

Hidding a column

mmontoyammontoya Posts: 84Questions: 27Answers: 4

From what I understand I need to have CustomerID as a field in the data table because I am referencing that field. I thought I saw a 'visible: false' option but it doesn't seem to work.

Here is what I have now:

          var table = $('#table').DataTable( {
              //jQueryUI: "true",
              //dom: "Tfrtp",
              lengthChange: false,
              autowidth: "false",
              ajax: "lib/getSearch.php",
              columns: [
                    {data: "Customers.CustomerID",
                      visible: false
                    },
                    {data: "Customers.FirstName"},
                    {data: "Customers.LastName"},
                    {data: "Customers.CustomerStatus",
                         render: function (val, type, row) {
                                      return val == 0 ? "Referral" : "Customer";}
                    },
                    {
                          data: "refBy",
                          render: function ( val, type, row ) {
                              return val.FirstName ?
                                  val.FirstName +' '+ val.LastName :
                                  '';
                          },
                          defaultContent: ""
                    },                    
                    {data: "Customers.City"}
              ]   
          } );

And I am looking for CustomerID in the following:

$('#table tbody').on( 'click', 'td', function () {
        var tr = $(this).closest('tr');
        var row = table.row( tr ); 
            $("#selectedID").val(row.data().Customers.CustomerID);
    } );

What do I need to do to hide the CustomerID column or not include it but still be able to reference it?

Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,787Questions: 1Answers: 10,115 Site admin
    Answer ✓

    There is indeed a columns.visible option which should work - however, I would suggest an easier option in this case, simply don't include it in the DataTables columns. It will still be in the data for the row, but there is no need to include it in the DataTable display (visible or not).

    Allan

  • mmontoyammontoya Posts: 84Questions: 27Answers: 4

    I thought I got an error saying CustomerID was unknown but I will try it again later and let you know how it goes.

    Thank you.

  • mmontoyammontoya Posts: 84Questions: 27Answers: 4

    I have a related question, do you think you can take a look at it?
    http://datatables.net/forums/discussion/29040/get-data-for-selected-row-for-tabletool-button#latest

  • mmontoyammontoya Posts: 84Questions: 27Answers: 4

    Ok. It did work to leave the column out completely. Not sure what I did wrong the first time I tried it.

    Thanks

This discussion has been closed.