RE: [PEAR-DEV] Proposal - HTML_DataGrid - Again
| From: | Andrew S. Nagy | Date: | Mon, 09 Feb 2004 14:33:33 +0000 |
| Subject: | RE: [PEAR-DEV] Proposal - HTML_DataGrid - Again | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-25555@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Hans Lellelid [mailto:hans@appliedsec.com]
>
> I was going to say this also. Yes, I don't think that it's the job of
> DataGrid to massage input types into some common format. If DB / MDB /
> DB_DataObject wants to support DataGrid natively, then it can implement
> the necessary method(s) to get data into the right format. Otherwise,
> as you said it's not too much work to just call the toArray() method.
>
I agree.
> If you're writing for PHP5 then you may note that the passed in value
> simply needs to implement an (SPL) iterator. That provides some
> additional flexibility.
>
I haven't yet had a chance to play with PHP5 much, I hope that someone will
be able to help me with this.
I also REALLY want to port this to a PECL package so that it offers a strong
competitor to c# datagrid.
> So, I would agree with you -- keep the input simple. For example, I'd
> like to also support creating DataGrid objects from my Creole/Jargon
> (http://creole.phpdb.org) DataSet class. I would think it would be my
> responsibility as calling package to make sure my data were in the
> correct format. E.g.
>
> $q = new Query($conn, "SELECT * FROM mytable");
> $dg = $q->getDataSet()->getDataGrid();
> // etc.
>
> On a side note, it would be nice (and maybe this has been mentioned
> already) to have a single method to set all the field key => name
> mapping -- using assoc array. Also, to make specifying columns optional
> (this may already be the case, but I thought I read that you had to
> setup the columns) so that the tool could be integrated into CMS-type
> systems where there wouldn't be any hard-coded expectations for which
> columns were being displayed.
>
Yes, this is done already. The datagrid will automatically set the field
names if you don't specify any, but will show all of the fields. This way
you can use the quick and dirty bind method to bind an associative array and
be off and running with just a few lines of code. If you specify any
columns, then only the columns you specify will show up.
> I haven't spent too much time looking at the code, but I was going to
> also suggest that things like links (href) should not be specified using
> the API; instead (IMHO) these should be part of a template or
> something.
I have implemented a column "formatter". This IMHO is really cool and an
invention of one of my co-workers. Basically you define a function that you
want to display the results of in the cell, and you can pass in elements
from the dataset. So I can have a printLink function or a printImage
function (shown in my example), or a printDropDown, etc. to show whatever
you want in the cell. As a quick and dirty way of printing a link, I have
that hardcoded into the column object so you can make a link easily with
little code.
I have not yet finished the formatter method, I still need to implement the
passing in of variables to the formatter function. I hope to finish this
soon.
As you can see, I am a big proponent of "Quick and Dirty" methods. The app
programmer should be able to implement the DataGrid with just a few lines of
code and get something very effective, this tends to damper the design of
the code a bit, but is nicer in the long run.
Andrew