PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
AddColumn callback problem

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures
View previous topic :: View next topic  
Author Message
Mungbeans



Joined: 10 Jan 2007
Posts: 30
Location: Sydney, Australia

PostPosted: Wed Feb 28, 2007 4:13 am    Post subject: AddColumn callback problem Reply with quote

I am attempting to have a column only print part of one of the fields thus:

Code:
   $datagrid->addColumn(new Structures_DataGrid_Column('Birth', null, 'dateofbirth', null, null, 'printBirth()'));

   function printBirth($params) {
      extract($params);
      $date = explode('-', $record['dateofbirth']);
               return $date[0];
   }


Unfortunately none of my callback functions are returning data. I've tested with straight functions such as
Code:
   function printBirth($params) {
               return 'test';
}


But nothing prints. I'm using the HTML_Table renderer - very similar to the complex example in the manual.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Wed Feb 28, 2007 3:28 pm    Post subject: Reply with quote

On a first (and quick) look, I don't see an error here. But the problem might be before these lines of code.

When do you call addColumn()? It needs to be called before bind(), for example.
Back to top
View user's profile Send private message
Mungbeans



Joined: 10 Jan 2007
Posts: 30
Location: Sydney, Australia

PostPosted: Wed Feb 28, 2007 11:54 pm    Post subject: Reply with quote

I'm having trouble working out where parts of the code go. If I place the bind method too early I get an error message, if I put it further down all the columns are blank. Here is the code:

Code:
   //create datagrid
   $datagrid =& new Structures_DataGrid(20);

   // Define columns - call before bind
   //$datagrid->addColumn(new Structures_DataGrid_Column(null, null, null, array('width' => '10'), null, 'printCheckbox()'));
   $datagrid->addColumn(new Structures_DataGrid_Column('Name', null, 'lastname', null, null, 'printFullName'));
   $datagrid->addColumn(new Structures_DataGrid_Column('Birth', null, 'dateofbirth', null, null, 'printBirth'));
   $datagrid->addColumn(new Structures_DataGrid_Column('Death', null, 'dateofdeath', null, null, 'printDeath'));
   $datagrid->addColumn(new Structures_DataGrid_Column('Edit', null, null, null, null, 'printEditLink'));

   // Specify how the DataGrid should be sorted by default
   $datagrid->setDefaultSort(array('lastname' => 'ASC',
   'firstname' => 'ASC'));
   
   // Define the Look and Feel
   $tableAttribs = array(
       'width' => '100%',
       'class' => 'sectiontable',
      'cellpadding' => '0'
   );
   
   $rendererOptions = array(
       'sortIconASC' => '⇑',
       'sortIconDESC' => '⇓'
   );   
   
   // Create a HTML_Table
   $table = new HTML_Table($tableAttribs);
   $thead =& $table->getHeader();
   $tbody =& $table->getBody();
   $tfoot =& $table->getFooter();
   
   
   $test = $datagrid->bind($rows);
   if (PEAR::isError($test)) {
       echo $test->getMessage();
   }
   
   // Ask the DataGrid to fill the HTML_Table with data, using rendering options
   $test = $datagrid->fill($table, $rendererOptions);
   if (PEAR::isError($test)) {
       echo $test->getMessage();
   }
   
   // Set attributes for the header row
   $headerAttribs = array();   
   $thead->setRowAttributes(0, $headerAttribs);
   
   // Set alternating row attributes
   $evenRowAttribs = array(
       'class' => 'sectiontableentry1'
   );
   $oddRowAttribs = array(
       'class' => 'sectiontableentry2'
   );
   $tbody->altRowAttributes(0, $evenRowAttribs, $oddRowAttribs, true);
   
   //Display paging links in the footer
   $footer[] = $datagrid->getOutput(DATAGRID_RENDER_PAGER);
   if (PEAR::isError($test)) {
       echo $test->getMessage();
   }
   $footerAttribs = array('colspan'=>'4');   
   $tfoot->addRow($footer, $footerAttribs, 'th');
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Thu Mar 01, 2007 11:18 am    Post subject: Reply with quote

Quote:
If I place the bind method too early I get an error message [...]


*argh* And what is this error message?

BTW: This does not make sense:

Code:

   $footer[] = $datagrid->getOutput(DATAGRID_RENDER_PAGER);
   if (PEAR::isError($test)) {
       echo $test->getMessage();
   }
Back to top
View user's profile Send private message
Mungbeans



Joined: 10 Jan 2007
Posts: 30
Location: Sydney, Australia

PostPosted: Fri Mar 02, 2007 12:45 am    Post subject: Reply with quote

Sorry, I got it while I was playing around trying to find the correct order for the bind method. I can't seem to replicate it now.

And, yes, that error trapping makes no sense where it is.

I've settled with putting the bind method just before creating the HTML_Table.

I've discovered that the problem seems to be with the add-column rows. If I comment these rows out it out all the data fills out the table. If I add the
add-column rows back but without the callback functions these also fill the data correctly.

So my problem seems definitely to be with the callback functions. I have one set up for testing purposes:

Code:
   $datagrid->addColumn(new Structures_DataGrid_Column('Edit', null, null, null, null, 'printEditLink'));

function printEditLink() {
  print 'test';
}



The callback functions are created within the function that creates the table (similar to the complex example). I experimented by moving them outside the function, and all their output printed at the top of the page .
Back to top
View user's profile Send private message
Mungbeans



Joined: 10 Jan 2007
Posts: 30
Location: Sydney, Australia

PostPosted: Fri Mar 02, 2007 12:48 am    Post subject: Reply with quote

Nevermind! Solved it.

If the callback functions are outside the calling function it works correctly. My above example used "print" instead of "return". They work now. I've been spending too much time using ajax.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software