Getting a hidden column's data in href link

Getting a hidden column's data in href link

mRendermRender Posts: 151Questions: 26Answers: 13

I have 10 columns, but my first 2 are hidden. In the last column, I have a link that I want to edit the URL for GET variables.
So how would I get the details.php?ID='THE HIDDEN COLUMN INFORMATION"

columns: [
            { data: "name" },
            { data: null, render: function ( data, type, row ) {
                // Combine the first and last names into a single table field
                return data.address+' '+data.city+' '+data.state+' '+data.zip;
            } },
            { data: "tel" },
            { data: "cell" },
            { data: "email" },
            { data: "status" },
            { data: "project_created",
              type: "date" },
          {
            data: null,
            className: "center",
            defaultContent: '<a href="details.php?='+ data.column[0]'" class="editor_edit">Details</a>'
        }

I used to be able to get it like this but I don't know if this works anymore with the updated datatables.

$('td:eq(0)', nRow).html( '<a class="link" href ="details.php?ID='+aData[1]+'">'+aData[1]+'</a>' );

This question has an accepted answers - jump to answer

Answers

  • mRendermRender Posts: 151Questions: 26Answers: 13
    edited June 2014

    Update: I found rowCallback and this is what my code looks like now:

    rowCallback: function( row, data ) {
                  $('td:eq(7)', row).html( '<a class="link" href="details.php?ID='+data[1]+'">'DETAILS'</a>' );
              }
    

    It's giving me undefined instead of "DETAILS"

  • mRendermRender Posts: 151Questions: 26Answers: 13

    Whelp, never mind. Got it.

    rowCallback: function( row, data ) {
                  $('td:eq(7)', row).html( '<a class="link" href="details.php?ID='+data['PID']+'">Details</a>' );
              }
    

    My issue was that I was using old code and trying to force it in there. I also had to use data['FIELDNAME'] instead of the hidden index. Thanks for reading :)

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    I would suggest using columns.render. You already are for the first column, so the same basic idea can be applied to the last column.

    columns.defaultContent is static only, so that won't help.

    Allan

This discussion has been closed.