| View previous topic :: View next topic |
| Author |
Message |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Tue Oct 30, 2007 7:13 pm Post subject: How to use XML renderer driver |
|
|
Greeting. Couldn't quite figure out how to make use of the XML renderer driver with DataGrid. Any code snippet like what's in XLS.php header would be greatly helpful.
I am trying to convert MySql data in DataGrid to a XML file. Thanks everyone. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
Posted: Tue Oct 30, 2007 8:10 pm Post subject: |
|
|
Well, the basic usage is just this line:
| Code: |
$datagrid->render('XML');
|
Or, if you want to save it to a file:
| Code: |
$datagrid->render('XML', array('saveToFile' => true, 'filename' => 'example.xml'));
|
The tags that are used in the generated XML code can be customized via some options.
If you need more help on this topic, please ask more specific. |
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Tue Oct 30, 2007 8:56 pm Post subject: |
|
|
| Wow. That's easy! I was thinking I need to instantiate a renderer object like in XLS or HTML table. Thanks for the quick response. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
Posted: Tue Oct 30, 2007 11:46 pm Post subject: |
|
|
| Arnold wrote: | | I was thinking I need to instantiate a renderer object like in XLS or HTML table. |
Hmm, what are you doing with XLS and HTML? For not too difficult/special cases, these renders work quite similar to my XML example here.
If you want, show some snippets from your code here, if you're not sure about it. (Of course, if you want, using your own Spreadsheet_Excel_Writer or HTML_Table object together with $datagrid->fill() is also fine, but maybe you have something else in mind with your sentence from above. |
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Wed Oct 31, 2007 2:34 am Post subject: |
|
|
| mark wrote: | | Arnold wrote: | | I was thinking I need to instantiate a renderer object like in XLS or HTML table. |
Hmm, what are you doing with XLS and HTML? For not too difficult/special cases, these renders work quite similar to my XML example here.
If you want, show some snippets from your code here, if you're not sure about it. (Of course, if you want, using your own Spreadsheet_Excel_Writer or HTML_Table object together with $datagrid->fill() is also fine, but maybe you have something else in mind with your sentence from above. |
I have been doing like what you said in the last paragraph. I create an instance of HTML_Table or Spreadsheet_Excel_Writer, set the options and call $datagrid->fill() and output the renderer data. Sample codes:
| Code: |
// Create the DataGrid, and bind the DataSource container
$datagrid = & new BarrelReportGrid($dataSource, $REPORT_MAX_BARRELS);
/*
* generate Spreadsheet
*/
$xls =& new Spreadsheet_Excel_Writer(); // create an instance
$worksheet =& $xls->addWorksheet('inventory');
$columns=9;
$worksheet->setColumn(0, $columns, 15); // set width for first 9 columns
$titleFormat = & $xls->addFormat();
$titleFormat->setBold();
$titleFormat->setAlign('left');
$worksheet->write(0,0,"INVENTORY", $titleFormat);
$worksheet->write(1,0,"SQL Search Criteria: ".$_SESSION['sessFilter'], $titleFormat);
$colHeadingFormat =& $xls->addFormat();
$colHeadingFormat->setBold();
$colHeadingFormat->setAlign('center');
$colFormat = &$xls->addFormat();
$colFormat->setAlign('left');
$options = array('headerFormat' => &$colHeadingFormat,
'bodyFormat' => &$colFormat,
'startRow' => 4,
'worksheet' => &$worksheet);
$datagrid->fill($xls, $options);
$xls->send('inventory.xls'); // send HTTP headers to tell the browser what's coming
$xls->close();
|
|
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
Posted: Wed Oct 31, 2007 3:38 pm Post subject: |
|
|
| Arnold wrote: | | I have been doing like what you said in the last paragraph. I create an instance of HTML_Table or Spreadsheet_Excel_Writer, set the options and call $datagrid->fill() and output the renderer data. Sample codes: [...] |
Okay, fine this way for such "complex" customizations. In the XML case, it's easier because there are not so many possibilities.
I have added an item on my TODO list about adding some more examples to the drivers. |
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Fri Nov 02, 2007 1:13 am Post subject: |
|
|
On a side note, XML renderer requires a newer version of DataGrid than I have so I updated to the latest 0.8.3 and all dependency libraries such as Pager. It appears to break all my pagers as I have been using renderer's getPaging() method. The header of renderer.php mentions that this function is now deprecated. But shouldn't it remain to work for old codes? Right now, it shows nothing. I have to change to the following method in order to get it working again.
| Code: | | $datagrid->getOutput(DATAGRID_RENDER_PAGER, $options); |
Just want to make sure this is the expected behaviour for getPaging() method. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
Posted: Fri Nov 02, 2007 1:18 pm Post subject: |
|
|
The new code (with getOutput()) looks fine, although you might want to use simply the string 'Pager' instead of the constant.
You haven't posted your old code, but I guess that you have used something like $datagrid->renderer->...? There was a backwards compatibility break in release 0.7.0 (or 0.7.1). The changelog will tell you more.
Otherwise, please show the relevant lines from your old code that now don't work anymore. |
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Fri Nov 02, 2007 6:18 pm Post subject: |
|
|
Yes, I have been using Structure_DataGrid 0.7.1 for a while now. The codes that I have been using are as follow with the renderer object being a HTML_Table.
| Code: |
$renderer =& $datagrid->getRenderer();
/* Get and output HTML links */
$pagingHtml = $renderer->getPaging(array('separator'=>'', 'mode'=>'sliding',
'prevImg'=>'<=', 'nextImg'=>'=>',
'delta'=>'5'
));
echo "<p class='paging'>Pages : $pagingHtml</p>";
|
I have installed the latest packages to work with the latest Structures_DataGrid. Perhap I am missing to install a package or so:
Structures_DataGrid_Renderer_XML
Structures_DataGrid_Renderer_Pager
XML_Util
HTML_Table
HTML_Common
Pager |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Fri Nov 02, 2007 9:45 pm Post subject: |
|
|
| I have no problem to utilize the new method for new codes. I just wish it is backward compatible so I don't need to modify my existing codes. This can be tedious but not a big deal. Cheers. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
Posted: Fri Nov 02, 2007 9:56 pm Post subject: |
|
|
| BC compatibility is also PEAR's and our (= Structures_DataGrid developers) goal, but the 0.7 release got a major refactoring and clean-up, and it was reasonable to make the Pager usage according to other drivers. The old way wasn't really extensible in terms of adding new drivers (for which it makes sense to use paging, too). For future releases, BC are very unlikely. |
|
| Back to top |
|
 |
|