|
How to reload a JQuery Datatables table data, using the API |
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:
So you cannot re initialise an existing dataTable object. Looking through the API methods there is a relatively straight forward fix.
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.
Glad I could help. You got it working now then?
http://www.trustedmontre.com
how to get more instagram likes
http://socialgrand.com/buy-instagram-likes/