Since I found the JQuery dataTables plugin, I use it quite a lot. I think it's a great way to display tabulated data, and it provides simple easy to use pagination and filtering options.
I've been building an interface to manage data, and arrived at the need to reload a datatable powered table, through a JavaScript request, rather than a page reload, or external variable (Url or form).
The problem with this is that if you try and re initialise a datatable into an existing datatable you get an error:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
DataTables warning: Unable to re-initialise DataTable. Please use the API to make any configuration changes required.
1DataTables warning: Unable to re-initialise DataTable. Please use the API to make any configuration changes required.
So you cannot re initialise an existing dataTable object. Looking through the API methods there is a relatively straight forward fix.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
if (typeof dTable == 'undefined') {
dTable = $('#example').dataTable( {
// data tables code
"bProcessing": true,
"bStateSave": true,
"bServerSide": true,
etc...
aoData.push({ "name": "pageFilter", "value": filterText });
});
else
{
dTable.fnDraw();
}
1if (typeof dTable == 'undefined') {
2
3 dTable = $('#example').dataTable( {
4 // data tables code
5 "bProcessing": true,
6 "bStateSave": true,
7 "bServerSide": true,
8etc...
9 aoData.push({ "name": "pageFilter", "value": filterText });
10 });
11else
12 {
13 dTable.fnDraw();
14 }
This code is basically checking if the object 'dTable' already exists, and if it is we are re drawing it, rather than using the existing object.
The fnDraw() method re-draws the table, so the data is refreshed. It uses the fnClearTable() method to first clear an existing data set, and the re draws it.
As an aside the 'filterText' value is a JavaScript value set elsewhere (a select field) that I am sending through to my server side request. It is used in a simple where clause in a query.