craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > General QuickTable Support/Help Post New Topic   Post A Reply
Formatting and calculating a totals row printer friendly version
next newest post | next oldest post
Author Messages
Safaga38
Private

Gender: Male
Location:
Registered: Aug 2008
Status: Offline
Posts: 5

Click here to see the profile for Safaga38 Send email to Safaga38 Find more posts by Safaga38 Edit or delete this message Reply w/Quote
Posted Sunday, November 23, 2008 @ 18:29:27  

Hi,

I have appended a totals row using the method insertEmptyRecord() at the end of a quicktable and have now the problem that all the totals in the row are not formatted. Which method do I have to call to manipulate the appearance of the row, for example to set the right cell renderer? Additionally: can I calculate the sum of a specific column without using a select statement, for example by adding all the values in a loop? I tried the following but it doesn't work:

c = auftragsTable.getColumn(4);
c.setReadOnly(true);
c.setType(Types.DOUBLE);
c.setPrecision(7);
c.setScale(2);
c.setUserCellRenderer(numericRenderer);
c.setHeaderValue("WW €");
c.setPreferredWidth(WLPTools.FRAME_WIDTH/11);
for(int i=0; i<auftragsTable.getRowCount(); i++) {
d = (Double)auftragsTable.getValueAt(i, 4);
sumWW += d;
}

where sumWW is the variable holding the sum of all values of a specific column.

Thanks for Your help

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Thursday, November 27, 2008 @ 08:31:56  

//after loading the data
dbtable.refresh();

//add the summary row
int totalRow = dbtable.getRowCount(); //if users add any rows,this row variable should be reset
dbtable.insertSilent(java.util.Vector insertElements, totalRow) ;

//initialize the summary row data
for(int i=1; i<=dbTable.getColumnCount() ; i++ )
{
Object newTotal = calculateTotalForColumn(i);
dbTable.setValueAt(newTotal, totalRow, i);
}

//listen for change in data and update summary row
class MyCellListener implements DBTableCellListener
{

public Object cellValueChanged(int row, int col, Object oldValue, Object newValue)
{
Object newTotal = calculateTotalForColumn(col);
dbTable.setValueAt(newTotal, totalRow, col );
return newvalue;
}

}

dbTable.addTableCellListener(new MyCellListener());

if you want to just change the foreground/background color/font/editable of the total row, then use CellPropertiesModel, refer api http://quicktable.org/doc/quick/dbtable/CellPropertiesModel.html

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios