Cannot get value from row cell when column is hidden

Cannot get value from row cell when column is hidden

fsweb2011fsweb2011 Posts: 3Questions: 2Answers: 0
edited April 2019 in Free community support

Hi there
I am using Datatables to convert a simple asp.net Gridview to a nice looking table with Databables.
I have some columns hidden, using ** { "targets": [ 7,8,11,12], "visible": false, }**,
This works well and columns are hidden correctly.

When I click on any of the rows, I would like to get the values from the hidden columns on that row into several textboxes.

I use for that the following function, but it doesn't work.

  $(function () {
        $("[id*=GridView1] td").click(function () {            
            DisplayDetails($(this).closest("tr"));
        });
    });

    function DisplayDetails(row) {       
     // copy values to Details table below        
        document.getElementsByName('TextBox3')[0].value = $("td", row).eq(10).html();
        document.getElementsByName('TextBox4')[0].value =$("td", row).eq(11).html();
        document.getElementsByName('TextBox5')[0].value = $("td", row).eq(12).html();
    }

If the column is NOT hidden then the textbox is filled correctly. However if the column is hidden, then I get an 'undefined' value on the correspoding textbox.
Any ideas how to solve?
thanks in advance.

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @fsweb2011 ,

    Functions like getElementsByName inspect the DOM - it would be better to use the DataTables function api data(), as hidden or not, the data will be returned. If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.