PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Structures » Structures_DataGrid_DataSource_DBQuery » Bug #7965

Please reintroduce sorting in DBQuery or MDB2

Details

Request #7965Please reintroduce sorting in DBQuery or MDB2
Submitted2006-06-22 16:34 UTC
Frombennythebee at gmail dot com
Assignedolivierg
StatusClosed
PackageStructures_DataGrid_DataSource_DBQuery
PHP Version5.1.4
OSDebian Sarge
Roadmaps(Not assigned)

Comments

[2006-06-22 16:34 UTC] bennythebee at gmail dot com

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?

[2006-06-22 16:47 UTC] bennythebee at gmail dot com

I just found out that it is also not working in the very Bug list on pear.php.net - try it out:

http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Structures_DataGrid&package_name[]=Structures_DataGrid_DataSource_Array&package_name[]=Structures_DataGrid_DataSource_CSV&package_name[]=Structures_DataGrid_DataSource_DataObject&package_name[]=Structures_DataGrid_DataSource_DB&package_name[]=Structures_DataGrid_DataSource_DBQuery&package_name[]=Structures_DataGrid_DataSource_DBTable&package_name[]=Structures_DataGrid_DataSource_MDB2&package_name[]=Structures_DataGrid_DataSource_RSS&package_name[]=Structures_DataGrid_DataSource_XML&package_name[]=Structures_DataGrid_Renderer_Console&package_name[]=Structures_DataGrid_Renderer_CSV&package_name[]=Structures_DataGrid_Renderer_HTMLSortForm&package_name[]=Structures_DataGrid_Renderer_HTMLTable&package_name[]=Structures_DataGrid_Renderer_Pager&package_name[]=Structures_DataGrid_Renderer_Smarty&package_name[]=Structures_DataGrid_Renderer_XLS&package_name[]=Structures_DataGrid_Renderer_XML&package_name[]=Structures_DataGrid_Renderer_XUL&status=All&search_for=sort&php_os=&boolean=0&author_email=&bug_type=&bug_age=0&bug_updated=0&order_by=status&direction=ASC&packagever=&phpver=&limit=40&handle=&assign=&maintain=&reorder_by=status

Regardless what table header column you click on, the sorting never takes place.

Tried with 2 OSs and 4 Browsers...

[2006-06-22 16:49 UTC] olivierg at php dot net

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

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

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:50 UTC] olivierg at php dot net

Yeah, and tell them to use SDG ;-)