Add Link in datatable with ajax
Add Link in datatable with ajax
Hi,
I have a datatable in my website, I get the data with ajax:
[code]
$('#counties').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),''&sIndexColumn=CountyId&sTable=County"
});
[/code]
I need a hiperlink in the fourth field, I don't know make this.
Thanks
I have a datatable in my website, I get the data with ajax:
[code]
$('#counties').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),''&sIndexColumn=CountyId&sTable=County"
});
[/code]
I need a hiperlink in the fourth field, I don't know make this.
Thanks
This discussion has been closed.
Replies
[code]
$('#counties').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),'[mRender:Activate]'&sIndexColumn=CountyId&sTable=County"
});
[/code]
But doesn't works.
Thks and Sorry me.
Allan
$('#counties').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
// Add link - start
"aoColumnDefs": [
{
"aTargets":[4],
"fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
{
$(nTd).css('text-align', 'center'); // center the link
},
"mData": null,
"mRender": function( data, type, full) {
return 'Add';
// Inplace of you can use
}
}
],
// Add link - end
"sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),'[mRender:Activate]'&sIndexColumn=CountyId&sTable=County"
});
[/code]
Drop the '' from the return. The cell already exists :-)
Allan
Jquery Source:
[code]
$('#counties').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{
"aTargets":[3],
"fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
{
$(nTd).css('text-align', 'center'); // center the link
},
"mData": null,
"mRender": function( data, type, full) {
return 'Add';
}
}
],
"sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),''&sIndexColumn=CountyId&sTable=County"
});
});
[/code]
This is HTML source
[code]
County
ID
Name
State
Action
[/code]
But doesn't work yet ... Sorry :(
Btw - passing SQL in sAjaxSource is very dangerous - a huge security whole in your app just waiting to be exploited!
Allan