How can i show data value hidden column?

How can i show data value hidden column?

CerditoCerdito Posts: 10Questions: 1Answers: 0
edited September 2020 in Free community support

Hi, when i hide a column, after i can't get the value if i put this html
<a>Date</a>: <output id="date"></output>

Code to hide column
"columnDefs": [ { "visible" : false, "targets": [2], "searchable": true} ],

My idea is: In this datatable show Name and Last name.

And if i click on Edit option i want to get Name, Last Name and Date. I Dont want show Date Column in the datatable, but if i hide the column i cant get the date value.

I dont know how to hide column and get the value with output for example.
Thanks

Replies

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    How are you fetching the row data now?

    The best way is to use row().data(). You can access the data from the hidden column.

    Kevin

  • CerditoCerdito Posts: 10Questions: 1Answers: 0
    edited September 2020

    This is all my code

    And html this

    How can i use row.data in my code to accesos the data hidden column?

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    I don't see the event handler for your button but that is where you would use it to get your row data. See this example:
    http://live.datatables.net/xijecupo/1/edit

    Kevin

  • CerditoCerdito Posts: 10Questions: 1Answers: 0
    edited September 2020

    This is the code from my edit button

    How can i add row().data() ?

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Is this using Editor? And how are you hiding the column? Are you using column().visible()?

    Colin

  • CerditoCerdito Posts: 10Questions: 1Answers: 0

    With this code

    "columnDefs": [
    { "visible" : false, "targets": [2], "searchable": true}
    ],

  • CerditoCerdito Posts: 10Questions: 1Answers: 0

    I used too column().visible()

    But i dont know how to show data from hidden column.

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    My example shows how to get data from the row of the clicked button. Here is the click event from one of the buttons:

    $('#example tbody').on('click', '.name', function () {
      var row = $(this).closest('tr');
      
      var data = table.row( row ).data().name;
      console.log(data);
    });
    

    You have fila = $(this).closest("tr");. To get the data use var data = table.row( fila ).data();. Your data is object based so use something like this to get the values:

    var first_name = data.first_name;
    var last_name = data.last_name;
    var date = data.date;
    

    Then use the data as you normally would.

    Kevin

This discussion has been closed.