From: Bernhard Harb on
Hello again!

I use structure_datagrid with MDB2 and smarty to print the data on the
screen. Everythings works fine, but there is one thing I have no
solution at the moment:
Is there a way to tell the datagrid, that a column should not be
printet, but it's content should be available? For example, I need the
ID of each record in every line because of links added to each lines
output. I there a way that I can get each lines ID without showing it
directly in datagrid?

Thanks a lot,
Bernhard.
From: Olivier Guilyardi on
Bernhard Harb a �crit :
>
> I use structure_datagrid with MDB2 and smarty to print the data on the
> screen. Everythings works fine, but there is one thing I have no
> solution at the moment:
> Is there a way to tell the datagrid, that a column should not be
> printet, but it's content should be available? For example, I need the
> ID of each record in every line because of links added to each lines
> output. I there a way that I can get each lines ID without showing it
> directly in datagrid?

Yes, you can do that, by setting columns up before bind(), using either
generateColumns() or addColumn(). If you don't, SDG automatically generates all
columns it finds in the datasource.

Example, to fetch id but hide it:
$datagrid->generateColumns('name' => 'Name', 'phone' => 'Phone number');
$datagrid->bind('SELECT id, name, phone FROM addressbook');

You may also use removeColumn() after bind() to drop some column.

Regards,

--
Olivier




From: Olivier Guilyardi on
Olivier Guilyardi a �crit :
>
> $datagrid->generateColumns('name' => 'Name', 'phone' => 'Phone number');

I meant:
$datagrid->generateColumns(array('name' => 'Name', 'phone' => 'Phone number'));

Regards,

--
Olivier
From: Olivier Guilyardi on
Bernhard, please:
1 - answer on the list
2 - answer in the body of the mail, not at the top.

Bernhard Harb a �crit :
> Thanks a lot! Any idea, if there is a chance to get the value of a
> hidden column with smarty renderer? I think smarty gets only the visible
> columns - does it?

Well, I'm afraid you can't do that, because of the way SDG tries to separate
presentation from data. Post a feature request if you like.

However, I suspect all you need is a column formatter, where you can access all
of the data. For example, to make a link:

function makeLink($data)
{
$id = $data['record']['id'];
$name = htmlspecialchars($data['record']['name']);
return "<a href=\"show.php?id=$id\">$name</a>";
}

$datagrid->generateColumns(array('name' => 'Name', 'phone' => 'Phone number'));
$datagrid->getColumnByField('name')->setFormatter('makeLink');
$datagrid->bind('SELECT id, name, phone FROM addressbook');

This way you'll get clickable names.

Regards,

--
Olivier



From: Bernhard Harb on
Olivier Guilyardi schrieb:
> Bernhard, please:
> 1 - answer on the list
> 2 - answer in the body of the mail, not at the top.
>
> Bernhard Harb a �crit :
>> Thanks a lot! Any idea, if there is a chance to get the value of a
>> hidden column with smarty renderer? I think smarty gets only the
>> visible columns - does it?
>
> Well, I'm afraid you can't do that, because of the way SDG tries to
> separate presentation from data. Post a feature request if you like.
>
> However, I suspect all you need is a column formatter, where you can
> access all of the data. For example, to make a link:
>
> function makeLink($data)
> {
> $id = $data['record']['id'];
> $name = htmlspecialchars($data['record']['name']);
> return "<a href=\"show.php?id=$id\">$name</a>";
> }
>
> $datagrid->generateColumns(array('name' => 'Name', 'phone' => 'Phone
> number'));
> $datagrid->getColumnByField('name')->setFormatter('makeLink');
> $datagrid->bind('SELECT id, name, phone FROM addressbook');
>
> This way you'll get clickable names.
>
> Regards,
>
> --
> Olivier
>
Ok, I got a way how to manage it. I added each column I want to access
but I do not want to show at the end of the column list and then I do a
$datagrid->fill($smarty)

In my Smarty template I do a {foreach} on every row and column and then
I check the columncounter inside each row and only print the column if
it is less then a specific value.

Of course, thats not the best way but I think it's the only way to
separate logic code and presentation code.

Cheers,
Bernhard.