fnRowSelected returning HTMLTableRowElement instead of id?
fnRowSelected returning HTMLTableRowElement instead of id?
ChrisG
Posts: 29Questions: 0Answers: 0
I can't seem to get the id to return on a selected row. Here's my code:
[code]
'oTableTools': {
'sRowSelect': \"multi\",
'fnRowSelected': function (nodes) {
alert( 'The row with ID '+ nodes[0] +' was selected' );
}
[/code]
This just gives me the following alert:
"The row with ID [object HTMLTableRowElement] was selected"
What's going on here? I pulled the code directly from the example for fnRowSelected... but I can't seem to get it to actually give me back the row info. I just want to get the id of the row.
[code]
'oTableTools': {
'sRowSelect': \"multi\",
'fnRowSelected': function (nodes) {
alert( 'The row with ID '+ nodes[0] +' was selected' );
}
[/code]
This just gives me the following alert:
"The row with ID [object HTMLTableRowElement] was selected"
What's going on here? I pulled the code directly from the example for fnRowSelected... but I can't seem to get it to actually give me back the row info. I just want to get the id of the row.
This discussion has been closed.
Replies
Allan
Allan
My ultimate goal is to then read this data when the table initializes and re-select rows that have a value of 1.
Essentially creating a serverside selecting that stores each row selection.
I feel like I've run into a wall with how to proceed from this point though. I'm assuming something to do with fnRowCallback and then getting the current row ids... then sending that info to the mysql server to retrieve the appropriate values for those rows... and then return that back into the restore function somehow and have it automatically select the proper rows.
I don't know though... I feel like I'm in over my head at this point. Any tips?
Allan
When a user selects a row, it calls a function with this inside. It basically sends the selected row as "row_#" and the username of the person logged in.
Then in process.php it connects to the database and does a mysql_query to update the user's account info to store that row selection info. Right now it's storing it in a field for each row... but I was only doing that to test. I think my best bet would be to store all the row selections as single numbers in a long string. For example if I have 10 rows, I could have a string representing 0's and 1's to show which rows have been selected or not (0 = not selected, 1 = selected)
So:
rows = "0100001000"
would mean that rows 2 and 7 are selected.
I just need to know how to best go about pulling that data from mysql, getting it into datatables and having it use that string to iterate through the rows and re-select the ones that should be selected.
I hope this makes sense.
You could do something like:
[code]
var ids = $.map( tt.fnGetSelected(), function ( i, row ) {
return row.id;
} );
[/code]
where `tt` is the TableTools instance for the table and assuming that each row has an ID. Then you'd just use the `ids` array as the data to submit to the server.
Allan
I was under the impression that mysql database variables can't be stored as arrays.
I think my bigger concern is just figuring out how to load the stored data and actually populate the selected rows from it. :(
> I was under the impression that mysql database variables can't be stored as arrays.
You are correct, MySQL doesn't have an array type. I don't quite understand why this is an issue though - shouldn't you be storing information for each row - which is presumably a row in the database?
> I think my bigger concern is just figuring out how to load the stored data and actually populate the selected rows from it. :(
Have you got the data being loaded? If so, that's a great step. The next one is to use fnGetData to get the data for the table and then loop through it. You'd check to see if a row is selected and then use the TableTools fnSelect method to select it on the client-side.
Allan
Storing each selected row individually in the row data itself would only work if a single user were selecting rows. I want it to be instanced per user so each user can store whatever selected rows they choose.
I don't have the data being loaded yet. I'm probably going to attempt saving it into the condensed string of numbers first and then run through those. Thanks for the info though... I think my plan now is to get the data loading from the mysql db, and then loop through the table and use the id numbers of the visible rows as the index to look at in the loaded string data... and then from there I can fnSelect them.
I'll give that a shot. :)