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

Request #3316 New datasource option : sort_default
Submitted: 2005-01-27 20:35 UTC
From: ylf at xung dot org Assigned: wiesemann
Status: Closed Package: Structures_DataGrid
PHP Version: 4.3.4 OS: Linux Debian
Roadmaps: (Not assigned)    
Subscription  


 [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".

Comments

 [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.
 [2006-04-25 09:14 UTC] wiesemann (Mark Wiesemann)
There is now a setDefaultSort() method in CVS.