cancel
Showing results for 
Search instead for 
Did you mean: 

sort table columns

Former Member
0 Kudos

Hey!

I got a table with some cols like Name, Changed, Status.

This resolves in a lot of rows, and it whould be perfect if the user could sort the rows after wich tableheader that was pressed.

I.E. a user press the column Name, it gets sorted on names, or if Changed is pressed, then its gets sorted on the dates.

Anyone got any clue of how this is possible?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

U have a calss called TableSorter which does this function.For step by step process,

Check out this thread which explains u clearly how it could be acieved:

Hope it helps,

Regards,

Nagarajan.

Former Member
0 Kudos

Thanx!

I have tried that, but i wasnt able to use the TableSorter class...

I have downloaded the TableSorter.java, but how can i add it in my project and use it as a type?

Former Member
0 Kudos

HI,

1)Adding TableSorter.java is simple in NWDS go to Navigator prespective paste the TableSorter.java file which you downloaded in the src->packes->the package which given for project.

2)Open the TableSorter.java file change the packge path.

just refersh and go to Web Dynpro prespective,

3)In the implemetation tab of the view add the sorce code which i mentioned

it will work, it worked for me..

Regards,

RK

Message was edited by: Ramakrishna Venkat

Former Member
0 Kudos

Thank you for your answere.

Now i have copied the TableSorter.java in the right folder in the navigation, and created a Context Attribute.

My question now is how to set the context attribute as a TableSorter type?

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Kristoffer,

by default the TableSorter automatically makes all table columns sortable (i.e. all context attributes). You just have to use the first constructor which does not have the String array parameter (IDs of sortable columns).

public static void wdDoModifyView(
   IPrivateWork wdThis, IPrivateWork.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
    if (firstTime) {
      IWDTable table = (IWDTable) view.getElement("CustomerTable");
      wdContext.currentContextElement().setCustomerTableSorter(
        new TableSorter(table, wdThis.wdGetSortCustomersAction(), null));
    }
    //@@end
  }

Regards, Bertram

Former Member
0 Kudos

Hi,

you created Context attribute for table sorter.

see the properties of that context attribute-> select Java Native type Radio button-> Browse (give TavleSorter) it will automatically display-> the given path(FOlder structure) and TableSorter (ie. com.abc.xyz.TableSoret) select this as type.

rest is in implemetation tab(Source code)

hope this solved your problme

Regards,

RK

Former Member
0 Kudos

Thank you for all your help.

I have managed to set the context type as a TableSorter, but when i compile i get alot of error from the TableSorter.java file.. Isnt it any classfile i also should include? cause the TableSorter doesnt deploy without a bunch of warnings and errors.

Former Member
0 Kudos

HI,

let's know what are all the steps you followed and what are the errors you are getting and when.

Regards,

RK

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

1)create a context valueattribute in the viewcontex and assign the the following type:

com.sap.tc.webdynpro.tests.utils.TableSorter

2)create a Action in your view for example:sortbyDate

3)assign this action to the table column properties that has to be sorted: Event / onAction sortbyDate

4) go to the implementation tab of your view controler and assign this code to the Action onActionsortbyTable:

wdContext.currentContextElement().getTableSorter().sort(wdEvent, wdContext.nodeDeMaintenenceOverview()); this sorts all elements in the specified valuenode(assigned to the table)

regards

Martin

Former Member
0 Kudos

First do this:

1.import the Tablesorter src/packages...

2. Switch to the Context tab page.

3. Using the secondary mouse button, click Context, choose New → Value Attribute, enter TableSorter as name, and confirm by pressing Finish.

4. Select the value attribute TableSorter and choose the type property in the lower window in the Properties tab.

5. Click the pushbutton …, choose Java Native Type and enter com.sap.tc.webdynpro.tests.utils.TableSorter. Confirm choosing OK.

via this example code you can access the sorter:

if (firstTime) {

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

wdContext.currentContextElement().setTableSorter(

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

}

and:

wdContext.currentContextElement().getTableSorter().sort(wdEvent, wdContext.nodeProducts());

You can use this URL to get a Tutorial on developing with tables. Pls use tutorial number 11 "Developing with tables"

regards

Martin Hastik

Former Member
0 Kudos

HI,

Refer this web log

/people/bertram.ganz/blog/2006/03/07/enhanced-web-dynpro-java-tablesorter-for-sap-netweaver-04s

I worked for Copmany code Bapi

1) In a table i displayed Company code (1st Cloumn) and Company Name (2nd Column) by excuting bapi in component controller

2) in View

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

{

//@@begin wdDoModifyView

if (firstTime) {

IWDTable table = (IWDTable) view.getElement("CompanyTable"); <b><----- [CompanyTable Table UI Name]</b> wdContext.currentContextElement().setSortCompanyName(

new TableSorter(

table,

wdThis.wdGetSortByCompanyNameAction(),

null));

}

//@@end

}

//@@begin javadoc:onActionsortByCompanyName(ServerEvent)

/** Declared validating event handler. */

//@@end

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

{

//@@begin onActionsortByCompanyName(ServerEvent)

wdContext.currentContextElement().getSortCompanyName().sort(

wdEvent,

wdContext

.nodeBapi_Companycode_Getlist_Input()

.nodeOutput()

.nodeCompanycode_List());

//@@end

}

hope this solves your problem

Regards,

RK