jQuery Datatables, Bulk adding rows with additional attributes
jQuery Datatables, Bulk adding rows with additional attributes
monkeytooth
Posts: 22Questions: 0Answers: 0
Currently I am adding rows to a datatable like:
[code]$.each(data.data.events, function(i, v)
{
var tobj = data.data.events[i];
var dateString = formatStatusDate(tobj.event_ts_begin);
statusMessageTable.fnAddData([
tobj.severity_icon,
tobj.event_severity,
tobj.type_icon,
tobj.event_code,
tobj.event_desc,
tobj.event_type,
tobj.event_text,
dateString
]);
var theNode = statusMessageTable.fnSettings().aoData[i].nTr;
theNode.setAttribute('data-idn',tobj.event_id);
});[/code]
However I have noticed this causes a great strain on the memory if there are more than 100 rows to add. Now I know many of you the first thought is, well why don't you render it via server side script, then apply your datatable logic. To that I say I can't to much of the page is dynamically generated by JS alone, as its mostly a javascript intense application.
So with that I am been trying to figure out a way to add all the rows I need down the line, while retaining the ability to add the attribute like I have being done. I am hoping someone more proficient than me with datatables may be able to help me figure something out, or offer some idea to what I can do to build out a object of sorts that can if possible be passed to the fnAddData function that will allow me at the same time to add that attribute to the parent row being added.
[code]$.each(data.data.events, function(i, v)
{
var tobj = data.data.events[i];
var dateString = formatStatusDate(tobj.event_ts_begin);
statusMessageTable.fnAddData([
tobj.severity_icon,
tobj.event_severity,
tobj.type_icon,
tobj.event_code,
tobj.event_desc,
tobj.event_type,
tobj.event_text,
dateString
]);
var theNode = statusMessageTable.fnSettings().aoData[i].nTr;
theNode.setAttribute('data-idn',tobj.event_id);
});[/code]
However I have noticed this causes a great strain on the memory if there are more than 100 rows to add. Now I know many of you the first thought is, well why don't you render it via server side script, then apply your datatable logic. To that I say I can't to much of the page is dynamically generated by JS alone, as its mostly a javascript intense application.
So with that I am been trying to figure out a way to add all the rows I need down the line, while retaining the ability to add the attribute like I have being done. I am hoping someone more proficient than me with datatables may be able to help me figure something out, or offer some idea to what I can do to build out a object of sorts that can if possible be passed to the fnAddData function that will allow me at the same time to add that attribute to the parent row being added.
This discussion has been closed.
Replies
Allan
I played with the idea of having the attribute added as a hidden column and pulling the attribute that way (or even itterating over the table and adding it afterward. Which sped it up some, but still that draw your talking about I think slows it down memory wise, nothing with your code, its all mine. But still lol, anyway to turn it off then back on?