on 06-03-2008 9:13 AM
hi experts,
I have a column of type string containing Amount + Currency values. How can I sort with respect to Amount only.
say 100 USD could be sorted based on 100 and USD field will not considered for sorting.
thanks in advance.
nikhil
1. Edit TableSorter.java
or
2. Use separate columns.
Thanks all
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nikhil,
I have got an idea. Create another string attribute ( say.. temp ) in the dataSource node of the table.
Now notice that the last 4 characters of the Amount + Curruncy string is always going to be a 3 letter currency (USD, INR, etc...) preceeded by a space. This format is fixed after the amount in the string. So u can make a substring of this amount excluding the '_USD' and save it in attribute temp in the node.
Now make another column in the table and map this attribute to the TableCellEditor of this new column. Make the visibility of this column as NONE.
When the user raise the event for sorting.. u can use the TableSorter on this invisible column containing the substring Amount value.
Hope this helps.
Regards,
Sayan Ghosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi..
While declaring the TableSorter attribute, we need to give the column name we want to sort.
like this...
Suppose teh anme of the table UI element id is Table1, attribute TableSorter is a context attribute of type TableSorter. Also the method in which the sorting is to happen is 'Sort' and the column id of the invisible colunm containing the substring Amount be 'Temp'.
Then...
public static void wdDoModifyView(IPrivatePO_Details wdThis, IPrivatePO_Details.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
if(firstTime)
{
IWDTable table = (IWDTable)view.getElement("Table1");
wdContext.currentVn_TableSorterElement().setVaIndex_TableSorter(new TableSorter(table, wdThis.wdGetSortAction(),null,new String[] {"Temp"}));
}
}
in the Sort Action.. call this TableSorter.
The actual values wont be replaced in the column.
Regards,
Sayan Ghosh
Hi Nikil,
Say you are using one node 'AmtCurr' and inside it you are having a value attribute of type String 'AmtCurr' where you are storing your Amount + currency values.
Now create one more value attribute say 'Amt' of type integer.
use this code to get the amount value in the value attribute Amt
int sizeAmtcurr = wdContext.nodeAmtCurr().size();
wdContext.nodeAmtCurr().moveFirst();
boolean NumExcep = false;
for(int i=0;i<sizeAmtcurr;i++)
{
String AmtCurr = wdContext.nodeAmtCurr().currentAmtCurrElement().getAmtCurr();
int count = 0;
int AmtCurLen=AmtCurr.length();
do
{
try {
String AmtStr = wdContext.nodeAmtCurr().currentAmtCurrElement().getAmtCurr();
AmtStr = AmtStr.substring(0,AmtCurLen-count);
int Amt = Integer.parseInt(AmtStr);
NumExcep = false;
wdContext.nodeAmtCurr().currentAmtCurrElement().setAmt(Amt);
} catch (NumberFormatException e) {
NumExcep=true;
}
count++;
}
while (NumExcep&&(count<AmtCurLen));
wdContext.nodeAmtCurr().moveNext();
}
Once this code is executed the amount value will be stored in the value attribute Amt.
Now call the method in Table Sorter passing this as the column.
You need not display this amount column to that user.
Hope this helps
Best wishes
Idhaya R
Hi Nikil,
Can you explain it a bit further...
Do you want it to be sorted by default or allowing the user to sort?
You can sort it by using number format exception.
Best Wishes,
Idhaya R
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you must modify the TableSorter.java file. It wont be easy.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.