DataTables Tutorial/how-to
DataTables Tutorial/how-to
So when it comes to Drupal, I have to admit that I don't really "get it" yet. I've installed datatables as a module, and I don't see anywhere in my Drupal admin pages anything about datatables. I can configure a table in views, but I suspect that's not it.
I found the page here: http://www.datatables.net/usage/
That says that I need to tell datatables how to draw my table, but I don't see how to accomplish that. How do I tell it about that table?
Also I found this:
$(document).ready(function() {
$('#example').dataTable();
} );
here: http://www.datatables.net/release-datatables/examples/basic_init/zero_config.html
But where do I put that code if I just wanted to get a basic table working on my site? Guess what I'm hoping to find is a simple tutorial on how to get started. Click this, paste that in there, edit etc . . . Like I said I don't "get" the whole Drupal thing yet, so any pointers would be greatly appreciated.
-S
I found the page here: http://www.datatables.net/usage/
That says that I need to tell datatables how to draw my table, but I don't see how to accomplish that. How do I tell it about that table?
Also I found this:
$(document).ready(function() {
$('#example').dataTable();
} );
here: http://www.datatables.net/release-datatables/examples/basic_init/zero_config.html
But where do I put that code if I just wanted to get a basic table working on my site? Guess what I'm hoping to find is a simple tutorial on how to get started. Click this, paste that in there, edit etc . . . Like I said I don't "get" the whole Drupal thing yet, so any pointers would be greatly appreciated.
-S
This discussion has been closed.
Replies
Although there might be a Drupal module (I honestly don't know!), DataTables is not considered a "Drupal thing" but rather a jQuery plugin.
Assuming the module is actually for the DataTables of this site (and not just a module for Drupal called "datatables" that's not related to jQuery DataTables plugin) it probably just adds the script to your site's head tag. From there, you are required to initialize any DataTables yourself.
So, wherever you put custom JavaScript code (maybe just between tags, though I suspect that's a non-Drupally approach), you need to do what's in the example you posted, except that the #example part is replaced with the ID of the table you wish to become a DataTables table.
To recap:
1. jQuery is included on your site. Maybe with Drupal this is done automagically? Or by adding a module?
2. DataTables.js is added to your site
3. A table is created on your page, either manually or through some Drupal plugin, but ideally just a plain table without styles or other shenanigans.
4. Somewhere on your page you have a script the executes the sample you provided, but with the ID of your own table.
5. ????
6. Profit!
-S