PEAR is archived and read-only

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

Home » Structures » Structures_DataGrid » Bug #3316

New datasource option : sort_default

Details

Request #3316New datasource option : sort_default
Submitted2005-01-27 20:35 UTC
Fromylf at xung dot org
Assignedwiesemann
StatusClosed
PackageStructures_DataGrid
PHP Version4.3.4
OSLinux Debian
Roadmaps(Not assigned)

Comments

[2005-01-27 20:35 UTC] ylf at xung dot org

Description:
------------
The following patch adds a new option available to all datasource drivers, namely : "sort_default". And it adds support for this option within the dataobject driver (TODO : other drivers need similar modifications).

http://samalyse.com/ln/0010.php

When the datagrid call datasource::fetch() without any sorting parameters this option gets used, thus enabling the developer to provide a default way of sorting the data.

Example :

$datagrid =& new Structures_DataGrid ();
$options = array(
'sort_default' => array('date','asc'),
);
$datagrid->bind ($dataobject, $options);

Will, by default, sort the data by "date".

[2005-01-27 22:49 UTC] asnagy at webitecture dot org

Why is this necessary, you can just as easy set the default by calling:

if (!isset($_GET['orderBy'])) {
$dg->sortArray = array('date', 'ASC');
$do->orderBy('date ASC');
}

Hmm... after looking at this I see your point that this should be a little more obvious/easier. Maybe a method called setDefaultSort() instead? I think that the sorting is such a major concept that it shouldn't be hidden in an option array.

[2005-01-28 15:13 UTC] ylf at xung dot org

Well, the orderBy GET parameter is somewhat internal to the datagrid. IMHO it has to be considered as a private property.

If calling setRequestPrefix() and/or displaying several datagrids, it may get really dirty to use a statement like the one you propose.

'Hidden in an option array' ? Many packages use option arrays, that's the first thing I look at when I need to customize a package's behaviour. What you call 'hidden' I call 'badly documented'.

Now, I understand your point : phpDocumentor() will show the setDefaultSort() method right out of the box, while option arrays usually requires end-user/external documentation.

Do as you prefer, a method or an option.