0

How to sum a column of a ListBox?

asked 2009-11-11 16:37:41 +0800

mguil gravatar image mguil
12

How is the best way to sum a column of a listbox and put the result in a footer?

Thanks
Manuel Guil

delete flag offensive retag edit

7 Replies

Sort by » oldest newest

answered 2009-11-11 18:44:26 +0800

samchuang gravatar image samchuang
4084 4

Do you use list model in listbox ?

the list size is the column number in list, is that you are looking for?

link publish delete flag offensive edit

answered 2009-11-12 05:36:14 +0800

mguil gravatar image mguil
12

Yes, I'm using a list model in listbox and want to sum the column with prices.

Thanks

link publish delete flag offensive edit

answered 2009-11-12 06:23:06 +0800

baskaraninfo gravatar image baskaraninfo
526 2 2 9

Whats problem in that?

Get the items list using List.getItems().
Then access the individual list items and do your sum calculation as per your requirement.

link publish delete flag offensive edit

answered 2009-11-12 07:36:53 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-11-12 07:37:19 +0800

For a few days i have work on my todo list and implement the outstanding ListFooter for summarizing a column field.
In my case i fill the ListFooter by a methode that made the summarizing with hibernate code in my DB-backend
because my listboxes are paging the data. Now the Listfooter shows all times the result of all affected records
independent of the listboxes page.

best
Stephan

link publish delete flag offensive edit

answered 2009-11-12 10:35:35 +0800

mguil gravatar image mguil
12

Baskaraninfo: Thanks for your answer, now i'm using List.getItems(), but I don´t like this way, when you change the list items the Listfooter doesn't refresh automaticaly...

Stephan: Your solutions sounds very good. Could you put a example of your summarizing methode.

Manuel
m.guil@encoweb.com

link publish delete flag offensive edit

answered 2009-11-12 14:00:31 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-11-12 14:01:49 +0800

It's Spring-managed Hibernate.

	/**
	 * Gets the sum for all 'aupGesamtwert' fields of the table orderPositions
	 * for an order (auftrag).<br>
	 * 
	 * (non-Javadoc)
	 * 
	 * @see de.daibutsu.backend.dao.AuftragDAO#getAuftragSumme(de.daibutsu.backend.model.Auftrag)
	 */
	@Override
	public BigDecimal getAuftragSumme(Auftrag auftrag) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Auftragposition.class);
		criteria.add(Restrictions.eq("auftrag", auftrag));

		ProjectionList proList = Projections.projectionList();
		proList.add(Projections.sum("aupGesamtwert"));
		criteria.setProjection(proList);
		BigDecimal sumResult = (BigDecimal) DataAccessUtils.uniqueResult(getHibernateTemplate()
				.findByCriteria(criteria));

		return sumResult;
	}

best
Stephan

link publish delete flag offensive edit

answered 2009-11-14 08:34:57 +0800

mguil gravatar image mguil
12

Your solution runs ok.

Thanks Stephan

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-11 16:37:41 +0800

Seen: 858 times

Last updated: Nov 14 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More