Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81997

fnGetData(): Can I get the actual object instance behind the row?

$
0
0
With fnGetData(row), I get back an Object with all my original properties + whatever other custom columns I've defined.

With more and more of my code moving to arrays of complex objects rather than 2d arrays of data, I want to be use the methods available on my 'typed' JS Objects.

function GameUser() {
    this.name = 'someridiculoushandle';
    this.score = 15; 
}
GameUser.prototype.incrementScore = function( ) { this.score += 1; return this; }

//paraphrased....
//bind array of GameUser to DataTable
aGameUsers = [new GameUser()];
dt.fnAddData(aGameUsers);
//click on row
data = dt.fnGetData(row)[0];
if(data instanceof GameUser) { //this is false
    //i want to be able to do this:
    data.incrementScore();
} 

So, can I get to my original objects somehow (either using fnGetData or otherwise)? I have factory methods that convert 'plain' objects into instances, but it seems like a waste when those instances already exist somewhere. I've also tried caching my objects in another array and then looking them up when I get the row data from fnGetData....but that makes me feel incompetent ;)

Viewing all articles
Browse latest Browse all 81997

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>