Get current dataTables

Get current dataTables

yazulyazul Posts: 3Questions: 0Answers: 0
edited March 2013 in General
Hi,

i use a javascript class, each object can create a datatables (each viewing a different SQL table).
how can i retrieve the current datatables when i select a row ?

i mean :

[code]
...
,"oTableTools": {
"sRowSelect": "single"
,"aButtons": [ ]
,"fnRowSelected": function(node) {
alert("select id="+node[0].id); // ok, i get the right id
}
}
...
[/code]

where can i store this id ?
"this" isn't the datatables, oTable isn't usable.
i mean something like "context" when using $.ajax()/

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Use `$('#{table-id}').dataTable()` .

    Allan
  • yazulyazul Posts: 3Questions: 0Answers: 0
    in fact, i don't know the datatable id !

    i must explain more :
    i have severals objects from same class.
    each object creates a datatable, using a unique name "dt_name"
    [code]
    MyObject.prototype= {
    ...
    dt_create: function() {
    $('body').append("...");
    this.oTable= $('#' + this.dt_name).datatables({
    ....
    "oTableTools": {
    ...
    "fnRowSelected": function(node) {
    // current node id is "node[0].id"
    // how to store this id in "this.current_id" or call this.setCurrentId()
    }
    }
    });

    }
    }

    [/code]
  • yazulyazul Posts: 3Questions: 0Answers: 0
    i reply to myself : this isn't a datatables'problem, but a JQuery/javascript problem.
    it's only a scope problem, i resolve it with such a (dirty) code :
    [code]
    ...
    var that= this;
    dt_create: function() {
    $('body').append("...");
    this.oTable= $('#' + this.dt_name).datatables({
    ....
    "oTableTools": {
    ...
    "fnRowSelected": function(node) {
    that.current_id= node[0].id;
    }
    }
    });

    [/code]

    of course !

    may be i can use $.proxy() too...
This discussion has been closed.