views:

410

answers:

4

For a long time in the Java/JSP world I used to use the Display Tag library to generate a table that would allow you to sort a table, and export the table as a CSV file.

Is there anything like this in a PHP library that I could use?

A: 

As far as I know PHP can't dynamically change the page (for sorting the table etc). You'd probably need to use something like javascript. I know that jquery has a table sort library.

PHP could do the CSV output. Make a link to a page that queries the database and uses the header() function to output a csv file - like this. Stackoverflow also has a couple similar solutions.

Good luck!

Matt
A: 

I think there is a method to deal with CSV in PHP. It is fputcsv(). It doesnt sort a table or anything like that it just converts an array into one line of csv.

Here is a link to it on the PHP website: http://us.php.net/manual/en/function.fputcsv.php

Josh Curren
A: 

You could try a scaffolder like -- http://www.aaronharp.com/2008/08/30/php-scaffold-class/ or -- cakephp. I don't think there is an included function that does that though.

CodeJoust
+1  A: 

The answer, from my searching, appears to be no. I wanted one too--love displaytag.

If you want a php only solution, Structures_DataGrid seems to be the best solution. Here's an article about it. This handles paging and sorting, but no exporting. Not sure how supported it is, either.

Another answer appears to be to use javascript to do paging and sorting, and roll your own php export functionality.

The state of the web is significantly different than it was when displaytag was created (ie, AJAX supported with a rich toolset), so I'm not sure there ever will be a full replacement. Why do sorting and paging with a call to the server when you can do it on the client?

Here's a jquery plugin that supports paging and sorting, and here's another one--all you need to do is have your php generate the table correctly.

As far as CSV exporting, there are tons of snippets out there. Here's one that looked good to me.

mooreds