Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.1.11

Request #7965 Please reintroduce sorting in DBQuery or MDB2
Submitted: 2006-06-22 16:34 UTC
From: bennythebee at gmail dot com Assigned: olivierg
Status: Closed Package: Structures_DataGrid_DataSource_DBQuery (version 0.1.0)
PHP Version: 5.1.4 OS: Debian Sarge
Roadmaps: (Not assigned)    
Subscription  


 [2006-06-22 16:34 UTC] bennythebee at gmail dot com (Benny Labach)
Description: ------------ I would really appreciate if sorting would be brought back into this (and MDB2) datasource driver. Right now, if I choose the HTML_SORTFORM or PAGER renderers, and try to use the sort links in the table header, there is no sorting taking place. If this functionality has been included in the renderers, wouldn't it make sense to make it work without userspace additions to the queries? The "old" way of using a DB Result object to bind and then Structures_DataGrid taking care of altering the queries to sort was the absolute best. Is it correct that rewriting the queries right now is a user task?

Comments

 [2006-06-22 16:49 UTC] olivierg at php dot net (Olivier Guilyardi)
The DB_Query and MDB2 drivers both support sorting by transparently modifying the queries. That's no user task. What is this "old way of using a DB Result object to bind and then Structures_DataGrid taking care of altering the queries to sort"? If you bind a DB_Result, how could Structures_DataGrid know about your original SQL queries? Actually, with a DB_Result, the whole data needs to be fetched, and sorting happens within the resulting PHP array. That's pretty inefficient. Don't confuse: $datagrid->bind($db_result); // use inefficient driver DB and: $datagrid->bind("select foo from bar"); // use DB_Query or MDB2 AFAICS, sorting works great with the MDB2 and DB_Query drivers. Maybe that you're using addColumn() and did not provide an $orderBy (third) argument to the Structures_DataGrid_Column constructor? Please post a test script.
 [2006-06-22 17:03 UTC] bennythebee at gmail dot com
Hello Olivier, I meant the old, inefficient way with the result object being fetched every time. Actually - I don't want to go back there either. I want to use DBQuery. What you say sounds interesting: "Maybe that you're using addColumn() and did not provide an $orderBy (third) argument to the Structures_DataGrid_Column constructor?" I am in fact using addColumn and a 3rd parameter: <?php require_once('Structures/DataGrid.php'); require_once('Structures/DataGrid/DataSource.php'); $datagrid =& new Structures_DataGrid(20); $datagrid->renderer->setTableAttribute('class', 'DataGrid'); $datagrid->renderer->sortIconASC = '⇑'; $datagrid->renderer->sortIconDESC = '⇓'; $datagrid->renderer->setTableEvenRowAttributes(array('class' => 'rEven')); $datagrid->renderer->setTableOddRowAttributes(array('class' => 'rOdd')); $dg = $datagrid->bind("SELECT POS,artist,title1,articlegroupcode,articleid FROM artist",array('dbc' => $db)); if (PEAR::isError($dg)) { echo $dg->getMessage(); } $datagrid->addColumn(new Structures_DataGrid_Column($tr->get("list_pos"), 'POS','POS',NULL,NULL,NULL)); $datagrid->addColumn(new Structures_DataGrid_Column($tr->get("list_artist"), 'artist','artist',NULL,NULL,NULL)); $datagrid->addColumn(new Structures_DataGrid_Column($tr->get("list_title"), 'title1','title1',NULL,NULL,NULL)); $datagrid->addColumn(new Structures_DataGrid_Column($tr->get("list_format"), 'articlegroupcode','articlegroupcode',NULL,NULL,NULL)); $datagrid->addColumn(new Structures_DataGrid_Column('id', 'articleid','articleid',NULL,NULL,NULL)); $dg = $datagrid->render(DATAGRID_RENDER_SORTFORM); if (PEAR::isError(dg)) { echo $dg->getMessage(); } $datagrid->render(); ?> Should this work without my interference with the Request params $orderBy or $direction?
 [2006-06-22 17:14 UTC] olivierg at php dot net (Olivier Guilyardi)
Well... I typed a bit fast. Sorting worked great in the MDB2 driver, but not in DBQuery. I've corrected the DBQuery::sort() method in CVS. Concerning the bug list at pear.php.net, I'm not aware that it's using Structures_DataGrid... I would be very honoured if that's the case ;-) Thanks for your report
 [2006-06-22 17:26 UTC] olivierg at php dot net (Olivier Guilyardi)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/Structures_DataGrid_DataSource_DBQuery
 [2006-06-22 17:27 UTC] wiesemann (Mark Wiesemann)
Although it may look like that, the bug tracker does not use SDG, see here: http://cvs.php.net/viewcvs.cgi/pearweb/public_html/bugs/stats.php?view=log Benny, please open a separate bug report about the not working sorting in the bug system here: http://pear.php.net/bugs/report.php?package=Bug+System
 [2006-06-22 17:50 UTC] olivierg at php dot net (Olivier Guilyardi)
Yeah, and tell them to use SDG ;-)