Restore Table Data

Restore Table Data

ValdreckValdreck Posts: 1Questions: 0Answers: 0
edited June 2011 in General
First of all, thxs for this nice plugin for jquery. Second sorry for my poor English :p
I don't know if there's a better way to make a copy of the initial table and restore it later when we have a dynamic source for the table...

I make this code for this purpose:
[code]
var oTable;
var giRedraw = false;
var tablebackup = new Array();

/* this function is not mine I picked from Internet
it fix the problem about outerhtml in firefox */
function getOuterHTML(object) {
var element;
if (!object) return null;
element = document.createElement("div");
element.appendChild(object.cloneNode(true));
return element.innerHTML;
}

$(function() {
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */

/* Init the table */
oTable = $('#table').dataTable( );
/*Backup the table*/
for(i in oTable.fnSettings().aoData)
tablebackup[i] = getOuterHTML(oTable.fnSettings().aoData[i].nTr);
});
});
[/code]

[code]
function table_reset()
{
oTable.fnClearTable();
for(i in tablebackup)
oTable.fnAddTr( $(tablebackup[i])[0] );
}
[/code]
Thxs,
Valdreck
This discussion has been closed.