 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
Mungbeans
Joined: 10 Jan 2007 Posts: 30 Location: Sydney, Australia
|
Posted: Wed Feb 28, 2007 4:13 am Post subject: AddColumn callback problem |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1003
|
Posted: Wed Feb 28, 2007 3:28 pm Post subject: |
|
|
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 |
|
 |
Mungbeans
Joined: 10 Jan 2007 Posts: 30 Location: Sydney, Australia
|
Posted: Wed Feb 28, 2007 11:54 pm Post subject: |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1003
|
Posted: Thu Mar 01, 2007 11:18 am Post subject: |
|
|
| 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 |
|
 |
Mungbeans
Joined: 10 Jan 2007 Posts: 30 Location: Sydney, Australia
|
Posted: Fri Mar 02, 2007 12:45 am Post subject: |
|
|
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 |
|
 |
Mungbeans
Joined: 10 Jan 2007 Posts: 30 Location: Sydney, Australia
|
Posted: Fri Mar 02, 2007 12:48 am Post subject: |
|
|
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 |
|
 |
|
|
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
|
|