| View previous topic :: View next topic |
| Author |
Message |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Tue Aug 14, 2007 1:40 am Post subject: Possible for DataGrid to display multiple records per row? |
|
|
DataGrid and QuickForm are two of my most often used PEAR packages. They have been working great for most of my backend application development.
I try to incorporate DataGrid to my current eCommerce application but realize this may be a challenge for the "frontend" part to display multiple products in single row as often that's the case for on-line shops such as osCommerce. Any insight if there are tricks to achieve that in DataGrid. If not, are there similar PEAR packages to do that? Thanks in advance. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Tue Aug 14, 2007 3:15 pm Post subject: |
|
|
What is your goal? Do you want to place your products like the following numbers?
1 2 3
4 5 6
7 8 9
If that's the case, I assume that you don't need column headers and no sorting (by clicking on the headers). You have at least two choices then:
- overload the HTML_Table renderer of SDG (buildBody() or buildRow()) and let it behave in the required way
- use HTML_Table directly: simply execute your SQL query, use a loop over the result set, and generate a new row for every (e.g.) third product
Otherwise, you might want to clarify what your goal is ... |
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Tue Aug 14, 2007 9:44 pm Post subject: |
|
|
| Thanks Mark, that's exactly what I intend to do. I think the first option (overload) seems to be a good solution to work seamlessly with SDG. Do you have any code snippet how to achieve that in HTML_Table? It should work with pager too, right? |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Tue Aug 14, 2007 10:02 pm Post subject: |
|
|
| Arnold wrote: | | Thanks Mark, that's exactly what I intend to do. I think the first option (overload) seems to be a good solution to work seamlessly with SDG. Do you have any code snippet how to achieve that in HTML_Table? It should work with pager too, right? |
Without paging, I'd say that using HTML_Table directly would be easier. With paging, the overloading solution might be easier.
You could start by looking at SDG_Renderer::buildBody() and SDG_R_HTMLTable::buildRow(). Your new class could extend the SDG_R_HTMLTable class by writing a constructor and your own buildBody() method. Instead of a new buildRow() method, you could directly place your code into the new buildBody() method. buildEmptyRow() shouldn't be needed for your class.
The idea of the HTML_Table renderer is that buildRow() is called for every record. You could loop over the records in buildBody(), using a counter for the columns -- after e.g. each third generated cell, you would set the counter back to 0 and start with a new table row.
If you need more hints, don't hesitate to ask. |
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Tue Aug 14, 2007 10:08 pm Post subject: |
|
|
| Thanks. That should get me going for now. I'll let u know if I get stuck. |
|
| Back to top |
|
 |
Arnold
Joined: 14 Aug 2007 Posts: 19 Location: Canada
|
Posted: Mon Aug 20, 2007 2:26 am Post subject: |
|
|
Hi Mark,
I have successfully made it to work. Essentially I am making a new custom renderer for SDG as you suggest. It does take me a while to figure out all the pieces as the custom renderer page for SDG on the pear website is a big empty.
For those who may be interested, this is how it is done and please point me out if there is better way to accomplish it. It will be better if there is way to do it without touching the DataGrid.php file.
In DataGrid.php, add your custom type (e.g. TABLE2 in my example)
define (DATAGRID_RENDER_TABLE2, 'HTMLTable2')
'html_table2' => DATAGRID_RENDER_TABLE2
create a new class file extending HTML_Table and place the new file HTMLTable2.php in Structures/DataGrid/Renderer
overload buildBody() and buildRow() in the new class file accordingly.
in main file, instantiate the new object and call setRenderer(DATAGRID_RENDER_TABLE2). pager will work by multiplying your specific number of records per row. for instance,
1234
5678
then the pass-in pager value should be 8.
I have been using style to suppress header in the past by setting the header attributes but it doesn't work with my new custom renderer for whatever reasons. so I have to hack it by setting $table->_thead = null. How should one hide the header info properly? |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Mon Aug 20, 2007 8:22 am Post subject: |
|
|
| Arnold wrote: | In DataGrid.php, add your custom type (e.g. TABLE2 in my example)
define (DATAGRID_RENDER_TABLE2, 'HTMLTable2')
'html_table2' => DATAGRID_RENDER_TABLE2 |
This is not needed and also not recommended (because you will lose the changes on every update). Simply put the name of your renderer as a string into the setRenderer(), render(), getOutput() etc. call.
| Arnold wrote: | | in main file, instantiate the new object and call setRenderer(DATAGRID_RENDER_TABLE2). |
See above, setRenderer('HTMLTable2') or specifying it in the render() call is better.
| Arnold wrote: | | I have been using style to suppress header in the past by setting the header attributes but it doesn't work with my new custom renderer for whatever reasons. so I have to hack it by setting $table->_thead = null. How should one hide the header info properly? |
That's described in the manual: Use the 'buildHeader' option:
| Code: | | $datagrid->render('HTMLTable2', array('buildHeader' => false)); |
Or, for your own renderer: Overload buildHeader() and let it do nothing. |
|
| Back to top |
|
 |
|