For about the last year and a half I have been using the awesome DataTables Plugin for jQuery. This is the most feature-rich and powerful javascript table plugin that I have come across and have been quite happy using it in various applications.
I decided to write a library to make it easy to render a DataTable in any application using any datasource. This library’s main aim is to provide a clean and simple object-oriented interface to build and render a DataTable. So far I have wrapped a majority of the features and options of the javascript plugin.
You can download the library here: http://github.com/lampjunkie/php-datatables
Check out the example in the “demo” folder for a full working example.
Thanks for making this public. I have a datatables project set-up, but need some more flexibility for server-side processing. This looks like a potential solution. However, I need a few pointers getting started. Would it be possible for you to put together a short example using mysql data? Thanks again for putting this out there.
Hi ko,
I’ve updated the demo in the GitHub repo so that there is an example of how to use php-datatables with mysql data. Basically, this new demo hands the data retrieval off to a service class which is then injected into the DemoDataTable object.
This demonstrates how you can use an existing data layer in your application (or create a new one) to handle the data retrieval and simply call that from within your DataTable. This is one of several ways to do it, but this is probably the best way to keep the DataTables decoupled from any specific data source.
Let me know if you need any more help!
-Marc
Hey Marc, good stuff, what is your take on the following:
1. Potentially reduce the number of files (currently 9) it takes to instantiate and process a single DataTables widget, the auto loader issues a number of file_exists calls which affects performance
2. Add support for multi-column sorting and request processor?
Hey Max,
1. I would suggest building a build script into your application which scans the php-datatables/src directory and combines the files into one. Then you can just include() that one generated file.
2. I updated the library on GitHub so that the DataTable_Request class has a new method (->getSortColumns()) which will return an array of all the currently sorted columns in the form: Column Index => Sort Direction. So that will provide anyone with the info they need to sort on multiple columns.
I also included an example of using it at the very end of the readme.md
Hope that helps!
-Marc