Re: DataGrid

From: Date: Sun, 24 Sep 2006 17:19:19 +0000
Subject: Re: DataGrid
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-25227@lists.php.net to get a copy of this message
On 9/24/06, Chris Boget <chris.boget@wild.net> wrote:
For the most part, DataGrid (coupled with DB_DataObject) is incredibly easy to use. In less than half a dozen lines of code, my query result set is returned in XML format. Very cool. I am, however, running into a stumbling block. One of my columns is a text field that contains/allows CRLFs, which I need to preserve. Before, when I queried the data manually, I was just able to pass that column on to nl2br() prior to display and all was good.
That is, of course, only preserving the format for HTML output. Preserving newlines would be actually leaving newlines as they are, which the XML renderer is almost certainly doing. Your XML reader, however is likely removing extra whitespace.
However, I don't see a way to pass the value of a column to a user defined function prior to the datagrid renderer using it.
Really? Did you look? One of the parameters to the Structures_DataGrid_Column class is a user-defined formatter function. See addColumn().
That's fine. So I try to do the replace in my query. I'll just use selectAdd() to select the column, having replaces the CRs with nothing and the LFs with '<br/>'. That works, but not how I expected. When the datagrid renderer (any of them, actually, not just the XML renderer) gets the value of the field, it 'prepares' it in some manner and turns any potential entity character into it's html entity representation. So my "<br/>"s are turned into "&lt;br/&gt;".
This is definately correct behavior for HTML and XML renderers. You don't want to allow HTML injection (XSS attacks). If it is happening for other renderers (such as text or XLS) then this is a bug.
It seems as if there is no way for me to, effectively, no way for me to perform any formatting (such as nl2br(), or any thing else that might involve entity characters). Is that the case?
No, see above.
I've tried to compensate in my XSL stylesheet but the only real option I could see was wrapping the node value in <pre></pre> tags. Anything else would cause all the text to run together as the CRLFs would not be preserved. But by using <pre>, any paragraph sized block would force the text off the right side of the page and cause the browser to create a horizontal scrollbar. Less than ideal presentation.
There should be a way to do a replace in XSL. In fact, a simple Google query for "XSL replace newlines" shows the answer in the first result.
Is there any way for me to get around this? Or am I just going to have to scrap my plans on using DataGrid? :(
-- Justin Patrin

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