Maybe I did not phrase my original the question well enough to get an answer. 

I have a simple DataTable containing - let call it sales records.  So, some
columns have numbers (eg, sales prices, sales commission, etc).  At the
bottom of the table, I need a row showing the of sales prices for all items
in the table.

I've done something like this in my Panel (this code has been chopped about,
so may not be correct - but you get the idea): 

public class SalesPanel extends PanelBase {

        private double totalSales = 0.0d;
        private Label totalSalesLabel = new Label("totalSalesLabel", "");
        private WebMarkupContainer listContainer = new
WebMarkupContainer("listContainer");
        
        public SalesPanel (String id) {
                super(id);
                
                listContainer.add(new DataView("sales", dataProvider) {

                     int i = 0;
                        
                     protected void populateItem(final Item item) {
                                
                        SalesItem salesitem = (SalesItem) item.getModelObject();
                                
                        item.add(new Label("salesref", String.valueOf(salesitem
.getRef())));

                        // add all the other columns here...
        
                        // increment the total
                        totalSales += salesitem .getSalesPrice();
                        totalSalesLabel.setModel(new Model(totalSales)); 
                  
                        i++; 
                        // if we are on the last row, reset the total to
zero so 
                        // total does not keep growing when panel is
redisplayed 
                        // it's on a cached tab
                        if(i == dataProvider.size()){ 
                          i = 0;
                          totalSales = 0;               
                        }
                     }
                });

            addLabels();
            add(listContainer);
      }
}


But maybe there is a better way.  

And maybe a way to do this in an AjaxFallbackDefaultDataTable? 

Steve





steve222 wrote:
> 
> What is the easiest way to get the final row in a table to show the column
> totals for numeric values?  No need for paging or sorting - just a simple
> table with column totals in the final row.  
> 

-- 
View this message in context: 
http://www.nabble.com/Easiest-way-to-add-column-totals-to-a-table--tp19927092p19978198.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to