How can I pass data through a link in the table?
How can I pass data through a link in the table?
I'm not sure exactly how I should be asking this question, so I'll be showing a lot of code.
This is the example I followed to build my table (Thanks for the examples btw, they are super helpful).
I have configured my table so that it works just like your example; however, I want to change what the edit button does.
I would like to be able to go to the location of that href (in the defaultContent), and pass the Primary Key (POs.pmkPOs) along with it - so I can use something along the lines of $_POST["PrimaryKey"]
on the other end to get the information.
var table = $('#POs').DataTable( {
dom: 'Bfrtip',
ajax: '.poView.php',
columns: [
{ "data": "POs.pmkPOs" },
{ "data": "POs.PONumber" },
{
data: null,
className: "center",
defaultContent: '<a href="POs.php" class="editor_open">Open</a>'
},
"columnDefs":
[{
"targets":[0],
"visible": true,
"searchable":false
}],
This is what the editor uses, but if I'm redirecting the page, I don't think it is really necessary. (?)
$('#POs').on('click', 'a.editor_open', function (e) {
e.preventDefault();
editor.edit( $(this).closest('tr'), {
title: 'Edit record',
buttons: 'Update'
} );
} );
Any tips would be greatly appreciated, Thanks for your time.
This question has an accepted answers - jump to answer
Answers
The
columns.defaultContent
option is useful, but it is only useful for static content (i.e. all rows are the same). If you want it to be dynamic (i.e. add a GET parameter to the URL which is different for each row), you'd need to use a renderer.If you read over the
columns.render
option you'll find an example for how to create a link based on the row's data.Regards,
Allan
Ah, thanks! That was super easy. Thank you.