You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Joost Schouten <jo...@jsportal.com> on 2007/07/06 06:54:47 UTC

[T5] Grid totals

Hi,

I just started to use tapestry and enjoy the ease of use. We use T5 and I am
currently developing some pages showing statistics information. I would like
to have a totals row at the bottom showing the sum of the columns shown. I
can easily add a row showing the totals for the whole table, but taking the
paginator into account makes it a bit more difficult.

Is this feature available, or has anyone done this before?

Thanks,
Joost





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Grid totals

Posted by Daniel Jue <te...@gmail.com>.
Joost, I see what you did there.  This is a clever hack, but I'm not
sure I want to get into DOM hacking with Tapestry. ;-)

Please let me know if you find a solution, and I'll do the same.
This is related to another more general question I'm going to post soon.

Daniel


On 8/1/07, Joost Schouten <jo...@jsportal.com> wrote:
> Daniel,
>
> In our current solution we disregarded the paginator and always show the
> total of all lines as showing page totals doesn't make sense in our
> situation. But implementing this should not be a big problem as you can just
> obtain the current page, the rows per page and thus generate your totals
> from it.
>
> Though my solution works, it feels like a hack and I will search for a more
> elegant way after our initial launch ;-)
>
> On my page/component implementing the Grid, I instantiate a new RowObject in
> a @SetupRender method, loop though all (or just current page on paginator)
> rows and sum the totals. Then in a @AfterRenderTemplate method I take the
> DOM and add a TFOOT containing the totals to the TABEL element.
>
> Below my (simplified) @AfterRenderTemplate method
>
> There will most likely be very nice and elegant ways to inject into or
> extend from the Grid component so everything can be done at the component
> level and not the DOM. But I just needed something to work right now ;-)
>
> Hope it helps,
>
> Joost
>
> -----------totals dom injection method------------------
>
> @AfterRenderTemplate
> void after(MarkupWriter writer){
>         //first find the table Element. T5 writes it in a div. Note that
>         //multiple tables in one component/page might cause issues
>         Element thisEl = writer.getElement();
>         Element table = null;
>         for(Node child : thisEl.getChildren()){
>                 if(child instanceof Element &&
> ((Element)child).getName().equalsIgnoreCase("div")){
>                         for(Node child1 : ((Element)child).getChildren()){
>                                 if(child1 instanceof Element &&
> ((Element)child1).getName().equalsIgnoreCase("table")){
>                                         table = ((Element)child1);
>                                         break;
>                                 }
>                         }
>                 }
>                 if(table!=null){
>                         break;
>                 }
>         }
>         if(table!=null){//is null when there is no data to display
>
>                 Element footerRow = table.element("tfoot").element("tr");
>                 int span = 1;
>                 String cellContent = null;
>                 String className = "cssStyleClass";
>                 if(this.rows != null){
>                         for(Iterator itr =
> yourBeanModel.getPropertyNames().iterator();itr.hasNext();){
>                                 String column = (String)itr.next();
>                                 if(column.equals("toTotalColumn1")){
>                                         //always first close the possibly
> open cell
>                                         writeFooterCell(footerRow,
> cellContent, span, className);
>                                         span=1;
>                                         className = "totalsmessage";
>                                         cellContent =
> yourTotalsRow.getTotal1();
>                                 }else if(column.equals("toTotalColumn2")){
>                                         writeFooterCell(footerRow,
> cellContent, span, className);
>                                         span=1;
>                                         className = "totalsvalue";
>                                         cellContent =
> yourTotalsRow.getTotal2();
>                                 }else{//all other columns just add a span
> and don't
>                                         //have a totals column
>                                         span++;
>                                 }
>                         }
>                         //write and close the last footer cell
>                         writeFooterCell(footerRow, cellContent, span,
> className);
>                 }
>         }//close block when table element is found
> }
>
> private void writeFooterCell(Element footerRow, String content, int span,
> String className){
>         if(content!=null){//if null, no open cell needs to be written as it
> is
>                                 //the first call toopen a cell
>                 Element footerCell = footerRow.element("td", "colspan",
>                                          Integer.toString(span), "class",
> className);
>                 footerCell.text(content);
>         }
> }
>
> -----Original Message-----
> From: Daniel Jue [mailto:teamphy6@gmail.com]
> Sent: Tuesday, July 31, 2007 4:53 PM
> To: Tapestry users
> Subject: Re: [T5] Grid totals
>
> Joost, How did you add a row for the totals while keeping that row
> from being sortable?
> I don't want to add it outside of the grid's table structure, because
> I want the columns to align.  I did this in T4 using code like this:
>
> <span jwcid="tableView">
> <table class="reportdata">
>
>         <tr>
>                 <span jwcid="@Contrib:TableColumns" class="literal:title" />
>         </tr>
>         <tr class="DataTotalsRow">
>         <span jwcid="aggregates@For" source = "ognl:AggregateList"
> value = "ognl:aggindex">
>         <td align="right" jwcid="@Any" title="ognl:aggindex.getToolTip()" >
>             <span  jwcid="@Insert"
> value="ognl:aggindex.getValue()">value</span>
>         </td>
>         </span>
>         </tr>
>         <tr jwcid="rows@Contrib:TableRows" class="ognl:beans.evenOdd.next">
>                 <td align="right" jwcid="@Contrib:TableValues" />
>         </tr>
>
> </table>
> <span jwcid="tablePages@Contrib:TablePages" /> </span>
>
>
> Perhaps I will need to "break open" Grid to get the same effect.
>
>
> As for your more specific issue, I am guessing you need to tap into
> the pager model to determine what indicies in your list are being
> displayed.  Maybe there is a way to implement your own pager that
> exposes the indice range that it will display, and then when rendering
> your totals row, you can tap back into your model and do calculations
> based on those indicies only.
>
> On 7/6/07, Joost Schouten <jo...@jsportal.com> wrote:
> > Hi,
> >
> > I just started to use tapestry and enjoy the ease of use. We use T5 and I
> am
> > currently developing some pages showing statistics information. I would
> like
> > to have a totals row at the bottom showing the sum of the columns shown. I
> > can easily add a row showing the totals for the whole table, but taking
> the
> > paginator into account makes it a bit more difficult.
> >
> > Is this feature available, or has anyone done this before?
> >
> > Thanks,
> > Joost
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: [T5] Grid totals

Posted by Joost Schouten <jo...@jsportal.com>.
Daniel,

In our current solution we disregarded the paginator and always show the
total of all lines as showing page totals doesn't make sense in our
situation. But implementing this should not be a big problem as you can just
obtain the current page, the rows per page and thus generate your totals
from it.

Though my solution works, it feels like a hack and I will search for a more
elegant way after our initial launch ;-)

On my page/component implementing the Grid, I instantiate a new RowObject in
a @SetupRender method, loop though all (or just current page on paginator)
rows and sum the totals. Then in a @AfterRenderTemplate method I take the
DOM and add a TFOOT containing the totals to the TABEL element.

Below my (simplified) @AfterRenderTemplate method

There will most likely be very nice and elegant ways to inject into or
extend from the Grid component so everything can be done at the component
level and not the DOM. But I just needed something to work right now ;-)

Hope it helps,

Joost

-----------totals dom injection method------------------

@AfterRenderTemplate
void after(MarkupWriter writer){
	//first find the table Element. T5 writes it in a div. Note that 
	//multiple tables in one component/page might cause issues
	Element thisEl = writer.getElement();
	Element table = null;
	for(Node child : thisEl.getChildren()){
		if(child instanceof Element &&
((Element)child).getName().equalsIgnoreCase("div")){
			for(Node child1 : ((Element)child).getChildren()){
				if(child1 instanceof Element &&
((Element)child1).getName().equalsIgnoreCase("table")){
					table = ((Element)child1);
					break;
				}
			}
		}
		if(table!=null){
			break;
		}
	}
	if(table!=null){//is null when there is no data to display

		Element footerRow = table.element("tfoot").element("tr");
		int span = 1;
		String cellContent = null;
		String className = "cssStyleClass";
		if(this.rows != null){
			for(Iterator itr =
yourBeanModel.getPropertyNames().iterator();itr.hasNext();){
				String column = (String)itr.next();
				if(column.equals("toTotalColumn1")){
					//always first close the possibly
open cell
					writeFooterCell(footerRow,
cellContent, span, className);
					span=1;
					className = "totalsmessage";
					cellContent =
yourTotalsRow.getTotal1();
				}else if(column.equals("toTotalColumn2")){
					writeFooterCell(footerRow,
cellContent, span, className);
					span=1;
					className = "totalsvalue";
					cellContent =
yourTotalsRow.getTotal2();
				}else{//all other columns just add a span
and don't 
					//have a totals column
					span++;
				}
			}
			//write and close the last footer cell
			writeFooterCell(footerRow, cellContent, span,
className);
		}
	}//close block when table element is found
}
	
private void writeFooterCell(Element footerRow, String content, int span,
String className){
	if(content!=null){//if null, no open cell needs to be written as it
is 
				//the first call toopen a cell
		Element footerCell = footerRow.element("td", "colspan",
					 Integer.toString(span), "class",
className);
		footerCell.text(content);
	}
}

-----Original Message-----
From: Daniel Jue [mailto:teamphy6@gmail.com] 
Sent: Tuesday, July 31, 2007 4:53 PM
To: Tapestry users
Subject: Re: [T5] Grid totals

Joost, How did you add a row for the totals while keeping that row
from being sortable?
I don't want to add it outside of the grid's table structure, because
I want the columns to align.  I did this in T4 using code like this:

<span jwcid="tableView">
<table class="reportdata">

	<tr>
		<span jwcid="@Contrib:TableColumns" class="literal:title" />
	</tr>
	<tr class="DataTotalsRow">
        <span jwcid="aggregates@For" source = "ognl:AggregateList"
value = "ognl:aggindex">
        <td align="right" jwcid="@Any" title="ognl:aggindex.getToolTip()" >
            <span  jwcid="@Insert"
value="ognl:aggindex.getValue()">value</span>
        </td>
    	</span>
   	</tr>
	<tr jwcid="rows@Contrib:TableRows" class="ognl:beans.evenOdd.next">
		<td align="right" jwcid="@Contrib:TableValues" />
	</tr>

</table>
<span jwcid="tablePages@Contrib:TablePages" /> </span>


Perhaps I will need to "break open" Grid to get the same effect.


As for your more specific issue, I am guessing you need to tap into
the pager model to determine what indicies in your list are being
displayed.  Maybe there is a way to implement your own pager that
exposes the indice range that it will display, and then when rendering
your totals row, you can tap back into your model and do calculations
based on those indicies only.

On 7/6/07, Joost Schouten <jo...@jsportal.com> wrote:
> Hi,
>
> I just started to use tapestry and enjoy the ease of use. We use T5 and I
am
> currently developing some pages showing statistics information. I would
like
> to have a totals row at the bottom showing the sum of the columns shown. I
> can easily add a row showing the totals for the whole table, but taking
the
> paginator into account makes it a bit more difficult.
>
> Is this feature available, or has anyone done this before?
>
> Thanks,
> Joost
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Grid totals

Posted by Daniel Jue <te...@gmail.com>.
Joost, How did you add a row for the totals while keeping that row
from being sortable?
I don't want to add it outside of the grid's table structure, because
I want the columns to align.  I did this in T4 using code like this:

<span jwcid="tableView">
<table class="reportdata">

	<tr>
		<span jwcid="@Contrib:TableColumns" class="literal:title" />
	</tr>
	<tr class="DataTotalsRow">
        <span jwcid="aggregates@For" source = "ognl:AggregateList"
value = "ognl:aggindex">
        <td align="right" jwcid="@Any" title="ognl:aggindex.getToolTip()" >
            <span  jwcid="@Insert"
value="ognl:aggindex.getValue()">value</span>
        </td>
    	</span>
   	</tr>
	<tr jwcid="rows@Contrib:TableRows" class="ognl:beans.evenOdd.next">
		<td align="right" jwcid="@Contrib:TableValues" />
	</tr>

</table>
<span jwcid="tablePages@Contrib:TablePages" /> </span>


Perhaps I will need to "break open" Grid to get the same effect.


As for your more specific issue, I am guessing you need to tap into
the pager model to determine what indicies in your list are being
displayed.  Maybe there is a way to implement your own pager that
exposes the indice range that it will display, and then when rendering
your totals row, you can tap back into your model and do calculations
based on those indicies only.

On 7/6/07, Joost Schouten <jo...@jsportal.com> wrote:
> Hi,
>
> I just started to use tapestry and enjoy the ease of use. We use T5 and I am
> currently developing some pages showing statistics information. I would like
> to have a totals row at the bottom showing the sum of the columns shown. I
> can easily add a row showing the totals for the whole table, but taking the
> paginator into account makes it a bit more difficult.
>
> Is this feature available, or has anyone done this before?
>
> Thanks,
> Joost
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org