cancel
Showing results for 
Search instead for 
Did you mean: 

Table Sorting

nikhil_bose
Active Contributor
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

nikhil_bose
Active Contributor
0 Kudos

1. Edit TableSorter.java

or

2. Use separate columns.

Thanks all

Former Member
0 Kudos

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

nikhil_bose
Active Contributor
0 Kudos

How this part can be done?

When the user raise the event for sorting.. u can use the TableSorter on this invisible column containing the substring Amount value

Does it replace actual column values?

nikhil

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

nikhil_bose
Active Contributor
0 Kudos

hi idhaya,

thanks for reply

I am using TableSorter.java and of course user initiates sorting.

nikhil

0 Kudos

you must modify the TableSorter.java file. It wont be easy.

Regards