Add link to cell but use a hidden field value to pass to function
Add link to cell but use a hidden field value to pass to function
 canwejustcode            
            
                Posts: 42Questions: 12Answers: 1
canwejustcode            
            
                Posts: 42Questions: 12Answers: 1            
            In my datatable, I need to create a link using <a href /> but pass a value of another cell for that row to a function to get executed to load a list box. I'm able to add the link using the <a hre=/> however, is there a way to get the value of the other cell for that row the user clicked the link in?
table = $('#output').DataTable({
     columns : [ 
              {
                  data : "id",
                  defaultContent: '',
                  render : function (data) { 
                             return  data
                       }
               },
               { 
                  data : "make",
                  render : function (data, type, value) {
                            "<a href="#" id="carMake" onClick="Process()"> + data + '</a>'
                   }
               }
       ]
})
I want to use the ID field to pass into the Process() function when they click on the { make } link.
This discussion has been closed.
            
Answers
See the
columns.renderdocs. The docs show the third parameter, calledrow, contains the data for the full row. Also see this example. Something like this should work:Note that I added
returnand changed some of the double quotes to single quotes to allow for imbedded double quotes in the string.Kevin
I looked at that and get { undefined } on the field I want to use for the link to pass to the JQuery function
I just noticed you have
valueas the name of the thirdcolumns.renderparameter. Either change it torowto match the docs or change therow.idtovalue.id.Kevin
I can combine the cells fine, it's when I wrap the <a href=" /> around it, it fails.
I took this line from the example
and tried it like this:
and I get the { undefined } message, however, I can combine both values in one cell just fine.
I get
{ uncaught reference error : 990 is not defined }
and 990 is the ID being passed
I got it working, I added an ID field so show the ID from the table, and now it works. Not sure why that would work, but I got it working