cancel
Showing results for 
Search instead for 
Did you mean: 

default sorting in table

Former Member
0 Kudos

Hi Experts,

I have a table which displays mdm data and i want the table to be sorted be default based upon a column when ever table screen is loaded.

Can some one help me with steps what to do and how to use or change the tablesorter class for this requirement

Thanks,

Anusha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Anusha,

1.Go to the Table Properties

Table--->table column---->sortstate-->

2.Create one context attribute type with TableSorter

3.add TableSorter.java file under src/packages/util

http://wiki.sdn.sap.com/wiki/display/devchallenge/TableSorter.java+For+WebDynpro

4.add the below code in the wddomodify view

if (firstTime){

        IWDTable documentListTable = (IWDTable) view.getElement("<table id>");

        wdContext.currentContextElement().setTableSorter(

        new TableSorter(documentListTable, wdThis.wdGetSortDocumentListAction(), null, new String[] { "<column name>" }));

       

        wdContext.currentContextElement().getTableSorter().sort_force("<column name>","sortstate",wdContext.nodeIt_Docs());

       

        wdContext.currentContextElement().setTableSorter(

                new TableSorter(documentListTable, wdThis.wdGetSortDocumentListAction(), null));

        wdContext.currentContextElement().setRows(0);

Regards,

Manivannan P

Former Member
0 Kudos

Hi Manivannan,

Thanks for the quick response.

Can you please give in more brief way as i do not understand

    wdContext.currentContextElement().getTableSorter().sort_force("<column name>","sortstate",wdContext.nodeIt_Docs());

i do not have any sort_force method in my tablesorter class and also u are passing column name to the tablesorter class.What changes do we need to do in table sorter class for adding column name also in parameter,

Thanks,

Anusha

Former Member
0 Kudos

Hello,

This is the custom method from the Tablesorter.java. You can use existing method or create custom method based on your sorting

eg:

            public void sort_force(String Column,String Direction, IWDNode dataSource) {

                                    // find the things we need

                                    String columnId = Column;

                                    String direction = Direction;

                                    IWDTableColumn column = (IWDTableColumn) table.getView().getElement(columnId);

                                    NodeElementByAttributeComparator elementComparator = (NodeElementByAttributeComparator) comparatorForColumn.get(column);

                       

                                    if (elementComparator == null){

                                                //not a sortable column

                                                column.setSortState(WDTableColumnSortDirection.NOT_SORTABLE);

                                                return;

                                    }

                       

                                    // sorting

                                    elementComparator.setSortDirection(WDTableColumnSortDirection.valueOf(direction));

                                    dataSource.sortElements(elementComparator);

                        }

Regards,

Manivannan P

Former Member
0 Kudos

Hi Manivannan,

Thanks i have implemented table sorter am able to see the table output and sort icon on column but sorting is not happening.Can you letme know what might be the problem

Thanks,

Anusha

Former Member
0 Kudos

Hi,

If you follow the above steps it should be an sort state. Please check once again.

Please check the code in wdDomodifyiew again

Syntax:

    wdContext.currentContextElement().getTableSorter().sort_force("<column name>","sortstate",wdContext.nodeIt_Docs());

Eg:

wdContext.currentContextElement().getTableSorter().sort_force("Status","up",wdContext.nodeIt_Docs());

also define in the Table column property-->sortstate

Regards,

Manivannan P

Answers (0)