cancel
Showing results for 
Search instead for 
Did you mean: 

Table Sort do not work

Former Member
0 Kudos

Hi,

I would like to sort columns in a table. i need the class TableSorter.java. i see the sort icon but the column do not sorted.

i need the "Developing with Tables in Web Dynpro" PDF for this implementation

have eny ideas wath is wrong

Message was edited by: Thomas Biedermann

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Stefanie,

Thanks for the reply. But I'm still not getting ascending icon.

I don't know what else to check

Former Member
0 Kudos

Hi Thomas,

I am facing similar problem. The link to the tutorial doesn't work. Or perhaps, do you still have the code, ie TableSorter.java ?

Regards

Former Member
0 Kudos

Hi Muhammad,

check out this blog:[Enhanced Web Dynpro Java TableSorter for SAP NetWeaver 04s|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/3287] [original link is broken] [original link is broken] [original link is broken];.

There you find links to the different versions of TableSorter: for NW2004 and for NW 7.0 also.

kind regards

Stefanie

Former Member
0 Kudos

hi,

1. i copied the TableSorter.java file to my packages folder

2. changed the package to biz.sfs.wd.mdeorders

3. i created an new Context Value Attribute TableSorter type Java Native Type TableSorter

4. defined the Table id with "TableHeaders"

5. created a new Action Sort

6. include the source code from the SDN Samples

7. deploye and run

8. the Sort Icon on the column are visible ASC and DSC but the Column are not sorted

-


<b>Code wdDoModifyView:</b>

public static void wdDoModifyView(IPrivateHeadersView wdThis, IPrivateHeadersView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

if (firstTime){

IWDTable table = (IWDTable) view.getElement("TableHeaders");

wdContext.currentContextElement().

setTableSorter(new TableSorter(table, wdThis.wdGetSortAction(), null));

}

wdThis.setLink();

//@@end

}

-


<b>Code onActionSort:</b>

public void onActionSort(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionSort(ServerEvent)

wdContext.currentContextElement().

getTableSorter().sort(wdEvent, wdContext.nodeOutput());

//@@end

}

-


Former Member
0 Kudos

Are you working with NW04 or NW04s? Is "Output" the table data source node?

Armin

Former Member
0 Kudos

Hi,

i work with NW04. the "Output" table date are correctly.

thomas

Former Member
0 Kudos

Add a debug output statement like

wdComponentAPI.getMessageManager().reportSuccess("...") inside the action handler, do you see the message when clicking the table header?

Armin

Former Member
0 Kudos

i see the message under the table

also the Action are run

thomas

Former Member
0 Kudos

What's the datatype of the attributes?

Armin

Former Member
0 Kudos

Java Native Type

biz.sfs.wd.mdeorders.TableSorter

Thomas

Former Member
0 Kudos

the table include SAP R/3 content.

is this a problem?

Thomas

Former Member
0 Kudos

What exactly are the data types of the table column attributes? The TableSorter can handle most simple types by default. For other types, you might have to pass suited comparators.

Armin

Former Member
0 Kudos

the table column attributes are a model types like this

biz.sfs.wd.mdeorders.model.types.Bstkd

i hope this is the info did you want?

thomas

Former Member
0 Kudos

This seems to be the reason. The TableSorter offers the possibility to pass an array of suitable Comparator instances for the individual columns. Can you try this?

Armin

Former Member
0 Kudos

sorry, i dont know wat you meen. im a greenhorn of web Dynpro development.

how can i do this....?

thomas

Former Member
0 Kudos

If I remember correctly, the last parameter of the TableSorter constructor (where you pass NULL) allows to pass an array of Comparator instances to help the TableSorter compare attributes with types it does not know about.

Check the source code of the TableSorter class accordingly.

A comparator for some type T can be implemented using an anonymous class, like


Comparator c = new Comparator()
{
  public int compare(Object o1, Object o2)
  {
    T t1 = (T) o1;
    T t2 = (T) o2;
    /* return 
      - negative value if t1 < t2,
      - positive value if t1 > t2,
      - 0 if t1 = t2 
    */
  }
}; 

Armin

Former Member
0 Kudos

hi,

ufff....

this is complicated for me...

wath are the alternative parameter for NULL

and wherefrom received the paramter value?

and where i must include the code

Comparator c = new Comparator()

{

public int compare(Object o1, Object o2)

{

T t1 = (T) o1;

T t2 = (T) o2;

/* return

- negative value if t1 < t2,

- positive value if t1 > t2,

- 0 if t1 = t2

*/

}

};

sorry

thomas

Former Member
0 Kudos

The constructor of class TableSorter looks like

public TableSorter(IWDTable table, IWDAction sortAction, Comparator[] comparators)

The last parameter is an (optional) array of comparators for each column. If this array contains a comparator at index i, it is used to sort the table by column i.

Example: (Editor of) column 2 is bound to an attribute of type "Employee" where

interface Employee
{
  public int getAge() {...}
  ...
}

Because the TableSorter does not know how to sort Employee objects by age, you must create a comparator and store it in the array at the column index.

/* Create an empty array */
Comparator[] columnComparators = new Comparator[<number-of-columns>];

/* Create a comparator that compares employees by age */
Comparator employeeByAge = new Comparator()
{
  public int compare(Object x, Object y)
  {
    /* cast to used type */
    Employee ex = (Employee) x;
    Employee ey = (Employee) y;
    /* compute and return comparison value */
    return ex.getAge() - ey.getAge();
  }
};

/* set array entry for column 2 */
columnComparators[2] = employeeByAge;

And this array is passed to the TableSorter constructor as the last parameter instead of NULL:

new TableSorter(table, action, columnComparators);

Effect: When you click on header of column 2, the TableSorter uses the employeeByAge comparator and the rows are sorted by employee age.

Armin

Former Member
0 Kudos

hi,

we tryed to include your code sample but we hade a lot of errors and we dont know how we are transfer the value x,y

could i send you the web dynpro project as zip file?

thomas

Former Member
0 Kudos

hi to all TableSorters

I downloadet the tablesorter class from the folowing link:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/tutorial...

then i changed the TableSorter.java in my project.

Now runs the TableSorter perfectly.

best regards

Thomas

Former Member
0 Kudos

My experience is that it is VERY important that the node which contains the data which should be sorted is a VALUENODE and not a MODELNODE!

Former Member
0 Kudos

Hi to all,

Thanks for so much help....

but i do not come the far. the table am simply not sorted?!?

other one ideas?

Thomas

Former Member
0 Kudos

Tell exactly what you have done. Without knowing this, it's difficult to help.

Arin

former_member182372
Active Contributor
0 Kudos

Hi Thomas,

Check

Best regards, Maksim Rashchynski.

Former Member
0 Kudos
Former Member
0 Kudos

hi,

i tried exactly this.

i created an new Value Attribute TableSorter with Java Native Type biz.sfs.wd.mdeorders.TableSorter

-


if (firstTime){

IWDTable table = (IWDTable) view.getElement("TableHeadersView");

wdContext.currentContextElement().

setTableSorter(new TableSorter(table, wdThis.wdGetSortAction(), null));

}

-


public void onActionSort(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionSort(ServerEvent)

wdContext.currentContextElement().

getTableSorter().sort(wdEvent,wdContext.nodeOutput());

//@@end

}

-


Regards

Thomas

Former Member
0 Kudos

Are you using NW04 or NW04s? The TableSorter from the tutorial works in NW04. For NW04s you have to adapt it.

Armin

Message was edited by: Armin Reichert

Former Member
0 Kudos

Hi,

Did u add ur Tablesorter.java file in the SRC package.

If so then in the wdDoModifyView check whether u have given the correct ID of the table.

if(firstTime)

{

IWDTable table = (IWDTable)view.getElement<b>("<Table ID>");</b>

wdContext.currentContextElement().setVa_Tablesorter(new TableSorter(table,wdThis.wdGetTablesortAction(),null));

}

Refer

Regards,

Nagarajan.