OnClick - Send to another page - Help
OnClick - Send to another page - Help
timcadieux
Posts: 76Questions: 22Answers: 0
Hi Folkz, I'm using this code which I found elsewhere in the Forums to allow myself to Click and open another page with the ID passed. It worked for me yesterday when I was using Server Side, but today, whenever I uncomment the commented lines below, it stops working? I can't figure it out?
Also, would it be possible to force it to open a target window, not the current?
Thx
[code]
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable( {
"bSortClasses": false,
"sDom": '<"top"i>rtlp<"clear">',
"oLanguage": {
"sSearch": "Search all columns:"
},
"sPaginationType": "full_numbers",
"aoColumns": [
/* ID */ { "bSearchable": false, "bVisible": false },
/* Surname */ null,
/* Given Name/Initial */ null,
/* Date of death */ null,
/* Rank */ null,
/* Service */ null,
/* Unit */ null,
/* Commemorated in
Country */ null,
/* Commemorated in
Cemetery/Memorial */ null
] ,
"bProcessing": true,
"sAjaxSource": 'json/' + sAlpha + '.txt',
"fnDrawCallback": function( oSettings ){
$('#example tbody tr').each( function() {
/* var iPos = oTable.fnGetPosition( this );
$(this ).click(function(){
window.location = "whatever.php?id="+oSettings.aoData[iPos]._aData[0];
});*/
});
}
} );[/code]
Also, would it be possible to force it to open a target window, not the current?
Thx
[code]
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable( {
"bSortClasses": false,
"sDom": '<"top"i>rtlp<"clear">',
"oLanguage": {
"sSearch": "Search all columns:"
},
"sPaginationType": "full_numbers",
"aoColumns": [
/* ID */ { "bSearchable": false, "bVisible": false },
/* Surname */ null,
/* Given Name/Initial */ null,
/* Date of death */ null,
/* Rank */ null,
/* Service */ null,
/* Unit */ null,
/* Commemorated in
Country */ null,
/* Commemorated in
Cemetery/Memorial */ null
] ,
"bProcessing": true,
"sAjaxSource": 'json/' + sAlpha + '.txt',
"fnDrawCallback": function( oSettings ){
$('#example tbody tr').each( function() {
/* var iPos = oTable.fnGetPosition( this );
$(this ).click(function(){
window.location = "whatever.php?id="+oSettings.aoData[iPos]._aData[0];
});*/
});
}
} );[/code]
This discussion has been closed.
Replies
Try this for your callback function:
[code]
"fnDrawCallback": function( oSettings ) {
$('#example tbody tr').click( function() {
var iPos = oTable.fnGetPosition( this );
alert( oSettings.aoData[iPos]._aData[0] );
//window.location = "whatever.php?id="+oSettings.aoData[iPos]._aData[0];
} );
}
[/code]
That seems to do the trick for me.
Allan
Thx
Anyway I can make the url target a new page?
Allan
I'll explain.
Using JSON, if i click on any row, a new page opens, that's fine.
If I type something in a filter and say get 5 rows, when i click on the first row, I get 5 windows that open, each with the ID of the first row.
Any way to avoid this?
Thanks for this one ... I have just chucked it into mine, I'm using Server-side pipelining, and upon filtering - and using window.open() - it only opens 1.
We've talked about this over e-mail, but here is a quick summary of the particular issue here, for the benefit of others.
That problem is that on each draw (ie. each latter press) fnDrawCallback is being run, and therefore adding another event handler to your TRs (Visual Event will show this). So what you want to do is use the fnInitComplete callback such that events are only added once. You'll also need to use fnGetNodes() in your event handler - see the post init demo here:
Regards,
Allan