Get value of row on another page
Get value of row on another page
New to the forums, sorry if this is in the wrong section!
Curious how I would get the value from a cell on a row that is located on another page in the table than the page I'm currently viewing.
If I look at the HTML in firebug it doesn't seem to be loaded on the page so it returns null when trying to access it.
Any ideas?
Curious how I would get the value from a cell on a row that is located on another page in the table than the page I'm currently viewing.
If I look at the HTML in firebug it doesn't seem to be loaded on the page so it returns null when trying to access it.
Any ideas?
This discussion has been closed.
Replies
However, it does not appear to work in any case.
I have a function that when I click on a button(update) it's supposed to fetch the ID's of the users in the table that needs updating from the database(this is done via an AJAX call) and then go through each one of those ID's and update the database(again with an AJAX call), after updated the PHP returns that it's been updated. I then have to fetch the row with the ID.
Each row has an ID of #user_, example: #user_734 for user with id 734.
So I tried:
[code]
var pos = oTable.fnGetPosition( '#user_' + id );
alert(pos);
[/code]
in the foreach loop. It gives me Javascript error:
[quote]
nNode.nodeName is undefined
ar sNodeName = nNode.nodeName.toUpperCase();
jquery.dataTables.js (line 1903)
[/quote]
Why's that?
fnGetPosition doesn't take a string as an argument, it takes a node ( http://datatables.net/api#fnGetPosition ) - although that's a nice idea for an extension.
What you need to do is something like this:
[code]
var nodes = oTable.fnGetNodes();
var jqRow = $(nodes).filter('#user_'+id);
[/code]
Allan
What exactly would the object of jqRow contain?
Do I need to do this?
[code]
var nodes = table1.fnGetNodes();
var row = $(nodes).filter( '#user_' + id );
var pos = table1.fnGetPosition( row );
var rowData = table1.fnGetData( pos );
[/code]
It still gives me the same kind of error :/
If you want the data then:
[code]
var nodes = oTable.fnGetNodes();
var tr = $(nodes).filter('#user_'+id)[0];
var data = oTable.fnGetData( tr );
[/code]
Allan
It's working now! :)
One more question though, is it possible to access the data based on what class the TD-cell has?
My HTML looks like this:
[code]
1
Allan
hello@yes.com
[/code]
I know I can access it with:
[code]
var data = oTable.fnGetData( tr );
alert( data[1] );
[/code]
to print the user name. Is it possible to access it with something along the lines of
[code]
$( data ).something( '.user_name' );
[/code]
???
Thanks for your help by the way! :)
if you don't want to hard code the column number like that, you can use some jquery to find out which column in "tr" has that class
[code]
var data = oTable.fnGetData( tr );
var username_col = $('.user_name', tr);
var colnum = $(tr).index(username_col);
var username = data[colnum];
[/code]
http://api.jquery.com/index/
In any case, I tried what you said and for some reason colnum returns -1, any idea why?
[code]
// Set up the base-DIV
var baseDiv = '#user_' + id;
// Get the correct node
var node = $( table1.fnGetNodes() ).filter( baseDiv )[0];
// Get the TR row-position from the node
var row = table1.fnGetPosition( node );
// Get the row-data
var rowData = table1.fnGetData( row );
alert(rowData);
// Username data
var column = $( '.user_name', row );
alert(column);
var username_col = $( row ).index( column );
alert(username_col);
var username = rowData[ username_col ];
alert(username);
[/code]
First alert outputs an array.
Second alert outputs an object
Third alert outputs -1
Last alert outputs "undefined"
Does it not find it because the row is on another page than the one you're on?
Perhaps I'll just have to use the row-array data instead..
but yes, you can iterate through the data in the datatables
oTable.fnSettings().aoColumns is an array of column objects. the aoColumn objects may have an sName, sTitle, sClass, or mDataProp and such, depending on how you initialize your datatable
best way to know which is worth using in your code is to return it in the debugger console and examine the fields your instance has filled in