I have a DataTable which is populated from a remote JSON DataSource:
var dataSource = new Y.DataSource.Get({ source: url });
dataSource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultListLocator: "results",
resultFields: [ "field1", "field2" ]
}
});
var table = new Y.DataTable({ columns = ["col1", "col2"] }
table.plug(Y.Plugin.DataTableDataSource, { datasource: dataSource });
table.render("#table");
table.datasource.load({ request: query });
I'm trying to have the data in the table refreshed periodically. A forum poster recommended calling load periodically, which I've tried and it works as I was hoping for (data refreshes without displaying a Loading... message).
Y.later(1000/*ms*/, table.datasource, table.datasource.load, { request: query }, true);
However, I've noticed a memory leak in Chrome. The table cells don't seem to be removed from memory. Chrome's heap profiler is reporting lots of HTMLTableCellElement objects in Detached DOM tree.
Is this the best method of refreshing the data? If so, is there some way to clear out the old table cells?
Alternatives
There is also the datatable-polling module that can do periodic fetching of data. I can't any examples of how this is supposed to be used with a YUI3 DataTable though. However, examples from YUI2 show you can do something the following, which appears to work:
dataSource.setInterval(1000,
{
request: query,
callback:
{
success: function(e) { table.onDataReturnInitializeTable },
failure: function() { Y.log("Polling failure", "error"); }
}
});
However, it looks like this is just what load is doing under the hood anyway:
load: function(config) {
config = config || {};
config.request = config.request || this.get("initialRequest");
config.callback = config.callback || {
success: Y.bind(this.onDataReturnInitializeTable, this),
failure: Y.bind(this.onDataReturnInitializeTable, this),
argument: this.get("host").get("state") //TODO
};
var ds = (config.datasource || this.get("datasource"));
if(ds) {
ds.sendRequest(config);
}
},