I'm missing something in your selector: you get some HTML from the TD in the eighth column (say, "mysite.com" as text, and then trying to find all elements that have the href "mysite.com", and then asking for their href. You're searching for something you've already found!
You can get attributes from hidden elements as long as they're hidden at the DOM level. If they're hidden by simply not rendering them, you could retrieve them from within the fnRowCallback or another convenient callback function.
I'm not sure what the end goal is, but one thing I do in one of my applications is to send the link as a whole separate hidden column. Then in fnRowCallback I get the value of that column (aData["linkColumn"]) and apply it to one of the visible rows:
[code]
fnRowCallback: function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
var theLink = aData['linkColumn'];
var clickableRow = 0; // zero-origin index; in this case my first visible row
if (theLink.length > 0) $('td:eq(' + clickableRow + ')', nRow).addClass('clickable').attr('href', theLink);
}
[/code]
So, instead of needing to get the HREF from the table to do something with it, I am coming from the opposite direction and setting the HREF on an element that needs it.
On the other hand, if your column is simply hidden with display:none or other CSS, you can still get the attribute... I'm just not sure what your scenario is; again, it seems like you're trying to ask for the HREF of "foo" for all elements that have the HREF of "foo".
Or was that your point; you just wanted to alert it to make sure it was a match?
Either way, a better understanding of your end goal would probably be useful: that way people can provide lateral-thinking suggestions instead of trying to resolve an unknown scenario.
Hope something I said here was vaguely helpful. ;-)
I am using this in Salesforce along with apex tags.
In order to get the actual URL I have to use a tag Called outPutLink. This adds the href to the actual output text...
i.e
This puts out the record ID say 0Ae000234958374AeF as the actual data in the and add the
so the text in underlined
What I did in the code above was to get the html of the td which returns JUST the id.
Then I search for the with an href*=THEIDVAR and it returns the link...
Now, if I use style="display:none" on the column tag, the text dissapears BUT the column is still visible in datatables and thus can be sorted (albeit the only indication is the small stub of the column and the sort arrows.
If I use datatables to hide the column then I can no longer get the data in column [8]
When I get the link I will be using it to open the link in a new window. I am also doing this so the user just has to click anywhere on the row and not an actual link in the table....
I just started using datatables and I am not much of a java programmer but I am learning. Right now my code is a mess....I should post it just for laughs :)
Here is the function I currently use with the visible column:
[code]
//get the value of the record ID column
j$('.datatable tbody tr').click( function () {
var b = j$('td:eq(8) span', this).html(); //returns the 18 chr record ID
var c = j$("[href$=" + b + "]").attr("href"); //returns the url in the href where the url contains the id
//Opens a new windows with the url
window.open(c,"FSA Display","menubar=no,scrollbars=yes,toolbar=no");
What you want is this plug-in: http://datatables.net/plug-ins/api#fnGetTds . Pass it in the TR element you want the TDs for, and it will return you the list of all TDs in the row, regardless of visibility.
The reason for this is that DataTables removes hidden column cells from the DOM, thus making a standard query not work. I've got plans to make that much easier in 1.9 :-)
I got it working EXCEPT for one thing. it only returns the first row......
When I use:
[code]
var aPos = tTable.fnGetPosition( this );
var anTds = tTable.fnGetTds( j$('[id$=fsaList] tbody tr:eq(aPos)')[0] );
[/code]
I get an error saying aoData is undefined. I can alert(aPos) and get the number of the row clicked but it does not appear to work in passing the parameter..
take apos out of the quotes
[code]
var aPos = tTable.fnGetPosition( this );
var anTds = tTable.fnGetTds( j$('[id$=fsaList] tbody tr:eq('+aPos+')')[0] );
[/code]
It works like a charm now..... I had to do some manupulation in other cells to get the href search to work since when I hid the 8th column the href tag went away as well.
Replies
You can get attributes from hidden elements as long as they're hidden at the DOM level. If they're hidden by simply not rendering them, you could retrieve them from within the fnRowCallback or another convenient callback function.
I'm not sure what the end goal is, but one thing I do in one of my applications is to send the link as a whole separate hidden column. Then in fnRowCallback I get the value of that column (aData["linkColumn"]) and apply it to one of the visible rows:
[code]
fnRowCallback: function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
var theLink = aData['linkColumn'];
var clickableRow = 0; // zero-origin index; in this case my first visible row
if (theLink.length > 0) $('td:eq(' + clickableRow + ')', nRow).addClass('clickable').attr('href', theLink);
}
[/code]
So, instead of needing to get the HREF from the table to do something with it, I am coming from the opposite direction and setting the HREF on an element that needs it.
On the other hand, if your column is simply hidden with display:none or other CSS, you can still get the attribute... I'm just not sure what your scenario is; again, it seems like you're trying to ask for the HREF of "foo" for all elements that have the HREF of "foo".
Or was that your point; you just wanted to alert it to make sure it was a match?
Either way, a better understanding of your end goal would probably be useful: that way people can provide lateral-thinking suggestions instead of trying to resolve an unknown scenario.
Hope something I said here was vaguely helpful. ;-)
In order to get the actual URL I have to use a tag Called outPutLink. This adds the href to the actual output text...
i.e
This puts out the record ID say 0Ae000234958374AeF as the actual data in the and add the
so the text in underlined
What I did in the code above was to get the html of the td which returns JUST the id.
Then I search for the with an href*=THEIDVAR and it returns the link...
Now, if I use style="display:none" on the column tag, the text dissapears BUT the column is still visible in datatables and thus can be sorted (albeit the only indication is the small stub of the column and the sort arrows.
If I use datatables to hide the column then I can no longer get the data in column [8]
When I get the link I will be using it to open the link in a new window. I am also doing this so the user just has to click anywhere on the row and not an actual link in the table....
I just started using datatables and I am not much of a java programmer but I am learning. Right now my code is a mess....I should post it just for laughs :)
[code]
//get the value of the record ID column
j$('.datatable tbody tr').click( function () {
var b = j$('td:eq(8) span', this).html(); //returns the 18 chr record ID
var c = j$("[href$=" + b + "]").attr("href"); //returns the url in the href where the url contains the id
//Opens a new windows with the url
window.open(c,"FSA Display","menubar=no,scrollbars=yes,toolbar=no");
} );
[/code]
and the init for the datatable is
[code]
tTable = j$(".datatable").dataTable({
// "aoColumns": [null,null,null,null,null,null,null,null,{"bVisible": false } ],
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"bSortClasses": false
});
[/code]
[code]
a0MJxxxx000E00H
[/code]
What you want is this plug-in: http://datatables.net/plug-ins/api#fnGetTds . Pass it in the TR element you want the TDs for, and it will return you the list of all TDs in the row, regardless of visibility.
The reason for this is that DataTables removes hidden column cells from the DOM, thus making a standard query not work. I've got plans to make that much easier in 1.9 :-)
Allan
I got it working EXCEPT for one thing. it only returns the first row......
When I use:
[code]
var aPos = tTable.fnGetPosition( this );
var anTds = tTable.fnGetTds( j$('[id$=fsaList] tbody tr:eq(aPos)')[0] );
[/code]
I get an error saying aoData is undefined. I can alert(aPos) and get the number of the row clicked but it does not appear to work in passing the parameter..
[code]
var aPos = tTable.fnGetPosition( this );
var anTds = tTable.fnGetTds( j$('[id$=fsaList] tbody tr:eq('+aPos+')')[0] );
[/code]
Thank you for that....
It works like a charm now..... I had to do some manupulation in other cells to get the href search to work since when I hid the 8th column the href tag went away as well.
I appreciate everyon's help with this!