Combining a URL with ID
Combining a URL with ID
mrgogo
Posts: 5Questions: 1Answers: 0
How to do
MY Codes:
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajax": "staff.php",
"table": "#example",
"fields": [ {
label: "First name:",
name: "first_name"
}, {
label: "Last name:",
name: "last_name"
}, {
label: "Position:",
name: "position"
}, {
label: "Office:",
name: "office"
}, {
label: "Extension:",
name: "extn"
}, {
label: "Start date:",
name: "start_date",
type: "datetime",
def: function () { return new Date(); },
format: 'DD.MM.YYYY HH:mm'
}, {
label: "Salary:",
name: "salary"
}
]
} );
var table = $('#example').DataTable( {
lengthChange: false,
ajax: {
url: "xxx.php",
type: "POST"
},
dom: "<'row'<'col-sm-6'><'col-sm-6'f>>" +"<'row'<'col-sm-12'tr>>" +"<'row'<'col-sm-5'li><'col-sm-7'p>>",
processing: true,
serverSide: true,
columns: [
{ data: "first_name" },
{ data: "last_name" },
{ data: "position" },
{ data: "office" },
{ data: "start_date"},
{ data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
],
select: true,
1rd try
"columnDefs": [ {
"targets": 1,
"data": "first_name",
"render": function ( data, type, row, meta ) {
return '<a href="URL\test.php?ID='+data.ID+'">'+data+'</a>'; }
}
]
this is returning http://URL/test.php?ID=undefined
2rd try
"columnDefs": [ {
"targets": 1,
"data": "first_name",
"render": function ( data, type, row, meta ) {
return '<a href="URL\test.php?ID='+data.RowID+'">'+data+'</a>'; }
}
]
this is returning http://URL/test.php?ID=undefined
3rd try
"columnDefs": [ {
"targets": 1,
"data": "first_name",
"render": function ( data, type, row, meta ) {
return '<a href="URL\test.php?ID='+data.DT_RowID+'">'+data+'</a>'; }
}
]
this is returning http://URL/test.php?ID=undefined
4rd try
"columnDefs": [ {
"targets": 1,
"data": "id",
"render": function ( data, type, row, meta ) {
return '<a href="URL\test.php?ID='+data+'">'+data+'</a>'; }
}
]
this is returning http://URL/test.php?ID=undefined
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Option 5 it is then :
I'm assuming here that you are using the Editor PHP libraries? The row id is stored in
DT_RowId
and the replace is used since a prefix ofrow_
is added by default (to make it a valid HTML_4_ ID).Note also the use of
row
rather thandata
. Thedata
property will point to whatever thefirst_name
value is in this case (e.g. whatcolumns.data
points to).Allan
Thank you very much for your help.