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

Getting data object from arbitrary table

$
0
0
Alrighty... so, I have a page with multiple tables on it. I initialize them like this:

fcmc.oTableAlarm = $('#alarm_overview').dataTable(fcmc.initializer("alarms"));
fcmc.oTableNodes = $('#nodes_overview').dataTable(fcmc.initializer("nodes"));
fcmc.oTableStats = $('#stats_overview').dataTable(fcmc.initializer("stats"));

(where the fcmc.initializer function returns an arguments object).

I have clickable elements in tables, which have custom classes ('.clickable') allowing me to bind an event to like this:

$('.container').on('click', '.clickable', function(e) {
// do stuff
});

Some of the "do stuff" portion would be much easier if I could access the original data. However, I don't know how to ascertain that "the cached DT object for this particular table is (for example) fcmc.oTableNodes" in order to call fnGetData() on it.

Consequently, I do this, and it does work:

$('.container').on('click', '.clickable', function(e) {
  var dataObj = $(this).closest('table').dataTable().fnGetData(this.parentNode);
  // do something with dataObj.someColumn
});

So... after that extremely long and example-heavy explanation, the simple question is this:

Am I unintentionally creating a new DT object with that last snippet? Ideally I would love to just be able to say:

var dataObj = fcmc.oTableNodes.fnGetData(this.parentNode);

and use the cached object; however I can think of no way of being aware within the click event that I need fcmc.oTableNodes. This is because the event should be able to fire on any table with '.clickable' elements. I could click the element in another table and actually need fcmc.oTableAlarms for example.

Any advice? Or even just a sanity check that the way I'm currently getting the data object is considered a perfectly acceptable practice?

Viewing all articles
Browse latest Browse all 82109

Trending Articles



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