RE: [PEAR] Structures/Datagrid - sorting on field prior to display with csv data source?

From: Date: Thu, 28 Dec 2006 14:38:00 +0000
Subject: RE: [PEAR] Structures/Datagrid - sorting on field prior to display with csv data source?
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26220@lists.php.net to get a copy of this message
Thank you Olivier, One very minor problem for me is that the column being sorted on isn't being tracked. For example, I'm sorting on my first column using setDefaultSort with ASC. This is called prior to the bind. Calling it after the bind and before the render wouldn't work. When the page is rendered the table is sorted correctly. If I click on the header for my first column, it will refresh the page with what I beleive is another ASC sort. It doesn't swith to DESC. You need to click twice on the column for it to switch direction in this case. Second issue is I can't get DESC to work. It isn't a major problem for me as I need ASC, but I wanted to test things out to make sure I have done things correctly. Here's my example code: <?php # Init Pear Datagrid for use require_once 'Structures/DataGrid.php'; $dg =& new Structures_DataGrid(); $dgOptions["generate_columns"] = true; $dgOptions["header"] = true; $dgOptions["labels"] = array ( "ln" => "Last Name", "fn" => "First Name" ); $preSort["ln"] = "ASC"; $result = $dg->setDefaultSort($preSort); if(PEAR::isError($result)) { echo $result->getMessage(); } # Bind our csv file to the datagrid $result = $dg->bind("./testdata.csv", $dgOptions, "CSV"); if(PEAR::isError($result)) { echo $result->getMessage(); } $drOptions["numberAlign"] = false; $result = $dg->render("HTMLTable", $drOptions); if(PEAR::isError($result)) { echo $result->getMessage(); } ?> Thanks again! > -------- Original Message -------- > Subject: Re: [PEAR] Structures/Datagrid - sorting on field prior to > display with csv data source? > From: Olivier Guilyardi <ojaiml@nerim.net> > Date: Wed, December 27, 2006 2:44 am > To: ScottZ <mylists@pinesalad.net> > Cc: pear-general@lists.php.net > > Hi ScottZ, > > ScottZ wrote: > > I'm having a bit of trouble when using a csv file with Structures/Datagrid. > > Is there a way to "pre-sort" the data on a particular field? > > You are looking for Structures_DataGrid::setDefaultSort() > > -- > Olivier

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