Re: Re: Datagrid and DataObject and performance

From: Date: Tue, 14 Dec 2004 00:13:35 +0000
Subject: Re: Re: Datagrid and DataObject and performance
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16216@lists.php.net to get a copy of this message
Andrew Nagy a écrit :
cron@odi.com.br wrote:
Hello Again, After look at the examples just find to be allot easier to just bind the data and let DataGrid do the work however I have this code and it does not work: $obj_db = DB_DataObject::factory('acesso'); $obj_db->find(); $dg = new Structures_DataGrid(4); $dg->bind($obj_db); $dg->render();
Your problem is calling the find method before the bind. Do not do this as DataGrid will call the find for you so that you can do sorting and paging. I apologize for any incorrect documentation, im working on it as we speak. I will look into the Source class ... I think it is called S_DG_DataSource but the filename is Source.php, so there may be a naming crisis here :) The DataObject source driver should be ready to go, I was doing some heavy testing on it today and I am 99% sure I have worked out all of the bugs, please get the latest from CVS and let me know if you find any bugs Thanks for the help and enjoy! Andrew Playing with the new tool (latest cvs), congratulations for the great job !
I would have a suggestion (from an idea of Alan Knowles in his DB_DataObject_Browse) : it would be nice if we could call some preFetch() (to make some more sorting or filtering) and postFetch() (to manipulate each row) method from the Structures_DataGrid_DataSource_DataObject::fetch() method : before fetching :
       if (method_exists($this->_do, $this->preFetchMethod)) {
           $this->_do-> {$this->preFetchMethod} ();
       }
while fetching :
           while ($this->_dataobject->fetch()) {
               if (method_exists($this->_dataobject, $this->postFetchMethod)) {
                   $this->_dataobject-> {$this->postFetchMethod}();
               }
               // Determine fields to render
               $rec = array();
               if ($this->_options['fields']) {
                   foreach ($this->_options['fields'] as $fName) {
                       $rec[$fName] = $this->_dataobject->$fName;
                   }
               } else {
                   // Can't use this until DB_DO Bug 1315 is fixed
                   //$rec = $this->_dataobject->toArray());
                                     // REPLACE ME WITH ABOVE
                   $rec = get_object_vars($this->_dataobject);
               }
               $records[] = $rec;
           }
For example a postFetch method could allow to set the value of a "virtual" field function postFetch(){ $this->totalNet=$this->getTotalNet();//with $this->fb_fieldsToRender['totalNet'] set and $totalNet as a member var } And a preFetch method could allow to set some global list's property (some sorting or filtering for example) This two method are useful to add more control on the lists. Regards, Didier

« previous php.pear.general (#16216) next »