Pass 'id' to Edit link in new column for user created edit page
Pass 'id' to Edit link in new column for user created edit page
Robertsuggs
Posts: 5Questions: 0Answers: 0
I have created a column (column 0) to have a hyperlink, so that when clicked will open another page (edit.php). I would like to pass the id (which is in column 1) to a link in this manner (edit.php?id='id from column 1). BTW, using server side processing.
Here is most of my javascript, which is where I think a change would need to happen. Currently, each "Edit" link has the value of null, because the mData is null (I think).
[code]
var asInitVals = new Array();
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"iDisplayLength":25,
"aLengthMenu":[[25,50,100,-1],[25,50,100,"ALL"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"aoColumns": [
{ "mData": null,
"mRender":function(data, type, full) {
return 'Edit';
}
},
{ "mData": 0 },
{ "mData": 1 },
{ "mData": 2 },
{ "mData": 3 },
{ "mData": 4 },
{ "mData": 5 }
],
"oLanguage": {
"sSearch": "Search all columns:"
},
} );
[/code]
I am very appreciative of anyone who can offer assistance. I have searched the forums for about 2 hours, but nothing seemed to work for me. Thanks!!
Here is most of my javascript, which is where I think a change would need to happen. Currently, each "Edit" link has the value of null, because the mData is null (I think).
[code]
var asInitVals = new Array();
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"iDisplayLength":25,
"aLengthMenu":[[25,50,100,-1],[25,50,100,"ALL"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"aoColumns": [
{ "mData": null,
"mRender":function(data, type, full) {
return 'Edit';
}
},
{ "mData": 0 },
{ "mData": 1 },
{ "mData": 2 },
{ "mData": 3 },
{ "mData": 4 },
{ "mData": 5 }
],
"oLanguage": {
"sSearch": "Search all columns:"
},
} );
[/code]
I am very appreciative of anyone who can offer assistance. I have searched the forums for about 2 hours, but nothing seemed to work for me. Thanks!!
This discussion has been closed.
Replies
Exactly that! Just set mData to the array index with your id in it - `0` in this case from what you say. The same data property can be used in multiple columns (as would be the case here) if you want :-)
Allan
[code]
{ "mData": 0,
"mRender":function(data, type, full) {
return 'Edit';
}
[/code]
My problem now is that the columns sort for the following column.
Columns: ID | NAME | EMAIL
When I sort ID, NAME is actually begin sorted, sort NAME and EMAIL is sorted. Off to search the forumns! Thanks Allan, great software you have here!
This script shows an example of mDataProp_{} being used on the server: https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/objects.php
Allan
I've looked at your example, but I'm not understanding what its telling me. Also, hasn't mDataProp been replaced with mData?
I think I need another nudge. Thank you!!
For initialisation yes. But not in what is sent to the server since that would break backwards compatibility - see the server-side documentation: http://datatables.net/usage/server-side .
> I just don't know how to tell it otherwise.
You need to make the column index to the data property. For example in my code:
[code]
$iColumnIndex = array_search( $_GET['mDataProp_'.$_GET['iSortCol_'.$i]], $aColumns );
[/code]
Exactly how you should do it will depend upon your own script and how it is constructed, but you need a mapping of some kind.
Allan
For some reason, when using the array_search function, I could never get a value assigned to $iColumnIndex. So I altered the code as follows:
[code]
$iColumnIndex = $_GET['mDataProp_'.$_GET['iSortCol_'.$i]];
[/code]
and it works great! Thanks for the help.