Shaun Mccran

My digital playground

02
J
U
L
2010

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:

view plain print about
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.

view plain print about
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.

Related Blog Entries

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Denis L's Gravatar Thank you so much for this post. I googled like 100 other posts before I got here and found this fix. thank you - thank you - thank you.
# Posted By Denis L | 29/01/2013 12:44
Shaun McCran's Gravatar Hi Denis
Glad I could help. You got it working now then?
# Posted By Shaun McCran | 30/01/2013 03:30
Liji's Gravatar I am very grateful to you for sharing such a useful article. I have searched a lot for getting the best information regarding hoe to reload a JQuery Datatables table data using the API. From this post I got the sufficient information. Thank you! http://www.goldenagecheese.com
# Posted By Liji | 08/06/2015 21:24
Qinsea's Gravatar Comment recharger un données de table JQuery datatables, en utilisant l'API
http://www.trustedmontre.com
# Posted By Qinsea | 23/06/2015 00:34
Whatefteld's Gravatar I am very happy with your article thank you, your blog is nice giving more information to all, I know about your http://topessaywriteronline.blogspot.com/ blog. I read your article frequently keep it up in the same way in future also.
# Posted By Whatefteld | 30/07/2015 08:16
EssayServiceReviews Company's Gravatar Thanks for helpful information. many reputable services, like http://essayservicereviews.blogspot.com/ struggle in order to attract more visitors and they do need such wholesome tips. By the way, you write very good, informative posts like an experienced academic writer and expliain everything in a clear manner, I want to wish you good luck!
# Posted By EssayServiceReviews Company | 06/08/2015 12:01
insta followers's Gravatar Struggle in order to attract more visitors and they do need such wholesome tips. By the way, you write very good, informative posts like an experienced academic writer and expliain everything in a clear manner, I want to wish you good luck!
how to get more instagram likes
http://socialgrand.com/buy-instagram-likes/
# Posted By insta followers | 08/10/2015 00:14
cardsharing's Gravatar Thank you so much for this post. I googled like 100 other posts before I got here and found this fix. thank you - thank you - thank you.
# Posted By cardsharing | 08/10/2015 00:48
roof shingles's Gravatar 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.
# Posted By roof shingles | 14/10/2015 06:19
Personal Injury Attorney's Gravatar You have raised an important issue..Thanks for sharing..I would like to read more current affairs from this blog.
# Posted By Personal Injury Attorney | 17/10/2015 03:21
view site's Gravatar You have raised an important issue..Thanks for sharing..I would like to read more current affairs from this blog.
# Posted By view site | 29/10/2015 04:53
Build My List 2.0 Jimmy Kim's Gravatar I want to encourage you to definitely continue your great job, have a nice weekend.
# Posted By Build My List 2.0 Jimmy Kim | 31/10/2015 05:28
clicking here's Gravatar Astfel, cu o minima investitie de bani si timp se poate evita o mare investitie ulterioara cauzata de eventuale probleme de dantura.
# Posted By clicking here | 05/11/2015 03:41
cccam server's Gravatar Rather than writing out long winded table code to display your data in a tabulated fashion why not use the dataTables JQuery plugin to do it for you...
# Posted By cccam server | 15/11/2015 03:25
amazon amz's Gravatar I see you got really very useful topics , i will be always checking your blog thanks....
# Posted By amazon amz | 16/11/2015 03:41
Language of Desire Free eBook's Gravatar I will be interested in more similar topics. i see you got really very useful topics , i will be always checking your blog thanks.
# Posted By Language of Desire Free eBook | 18/11/2015 02:26
aanrechtblad's Gravatar I found this post very exciting. I think you will have any other post on this topic? I am also sending it to my friend to enjoy your working style. Cheers!
# Posted By aanrechtblad | 18/11/2015 08:27
cccam server's Gravatar Thank you for your kind information. Actually I was very much sad that I couldn’t display dynamic data in tables. I have tried many methods and those were all failures. Now I am very happy in getting the perfect way to do this job
# Posted By cccam server | 21/11/2015 01:12
Travel Water Bottles's Gravatar 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).
# Posted By Travel Water Bottles | 30/11/2015 01:05
right here's Gravatar I just thought it may be an idea to post in case anyone else was having problems researching but I am a little unsure if I am allowed to put names and addresses on here.
# Posted By right here | 13/12/2015 22:03
top sellers on amazon's Gravatar I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.
# Posted By top sellers on amazon | 17/12/2015 05:57
E3-1240v2's Gravatar 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).
# Posted By E3-1240v2 | 19/12/2015 23:06
Certificate's Gravatar Great Post This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this..Thank You!
# Posted By Certificate | 21/12/2015 02:30
cheap research paper's Gravatar Firstly create a CurrencyFormatter object, and specify the currency symbol, and any other formatting parameters that you require.
# Posted By cheap research paper | 26/12/2015 03:00
buy garcinia cambogia's Gravatar I googled like 100 other posts before I got here and found this fix. thank you - thank you - thank you.
# Posted By buy garcinia cambogia | 27/12/2015 05:29
this link's Gravatar Good to become visiting your weblog again, it has been months for me. Nicely this article that i've been waited for so long.
# Posted By this link | 28/12/2015 01:53
this link's Gravatar Your site and show the kids check out up here generally. I m fairly positive there likely to be informed a great deal of new stuff here than anyone.
# Posted By this link | 29/12/2015 00:35
Unlock Her Legs's Gravatar Most of the time I don’t make comments on websites, but I'd like to say that this article really forced me to do so. Really nice post!
# Posted By Unlock Her Legs | 04/01/2016 00:50
Car Show Display Boards's Gravatar I’m now working with WordPress for a couple of with this blogs and forums nonetheless wanting to switch one of them over to your stand akin to you for a trial offer perform.
# Posted By Car Show Display Boards | 04/01/2016 22:08
The Bonding Code's Gravatar It was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity...
# Posted By The Bonding Code | 06/01/2016 23:30
Victorino Noval Foundation's Gravatar I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will locate that extremely useful...
# Posted By Victorino Noval Foundation | 11/01/2016 00:38
monthly boxes for men's Gravatar I’ve been thinking about writing a very comparable post over the last couple of weeks. I’ll probably keep it
# Posted By monthly boxes for men | 12/01/2016 22:41
bike transport pune's Gravatar I googled like 100 other posts before I got here and found this fix. thank you - thank you - thank you.
# Posted By bike transport pune | 13/01/2016 23:28
find a therapist's Gravatar So luck to come across your excellent blog. It is filled with interest that let me read relaxing.
# Posted By find a therapist | 14/01/2016 02:21
contact's Gravatar So luck to come across your excellent blog. It is filled with interest that let me read relaxing.
# Posted By contact | 19/01/2016 03:38
what is a ddos attack's Gravatar Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
# Posted By what is a ddos attack | 04/02/2016 01:17
Back to top