Problem in sorting of table data

Hi all,
I had gone through the PDF given (Developing with tables in webdynpro).
i got struck in creating TableSorter.java file...
can any one tell me how to create that java file in my project and how to send the colum which i want to sort to TableSorter.java
Regards
Padma

To implement it ,create a value attribute say "sorter" of java native type
com.sap.tc.webdynpro.tests.utils.TableSorter. (The package name MIGHT be different.)
In wdDoModifyView,obtaine a refernce to the table objject like
table = (IWDTable)view.getElement("table ui name);
and use
wdContext.currentContextElement().setSorter(
new TableSorter(table, wdThis.wdGet
<action name for sort>Action(), null));
Now inside that action handler,
wdContext.currentContextElement().getTableSorter().sort(wdEvent,
wdContext.node<nodename>());
also chk it
Re: Sort a table
sort table columns
Table Sorting ( In Case Insensitive order)
null

Similar Messages

  • Character problem in toad import table data from excel

    Hi everybody,
    I want to import data from an excel file to an Oracle table, so I'm using Toad's "Import Table Data" tool for this purpose.
    The problem is Oracle doesn't import non-english characters properly.
    My database is XE and character set is 'AL32UTF8'.
    I searched web, but didn't find the solution.
    Please help...

    Hi again,
    Thank you for your reply Srini, but it is not about Toad.
    Character encoding of Excel causes the problem.
    I exported an unicode encoded csv file from excel and tried to load data from that file. It worked.
    Thanks.

  • Physical Sort on Table data

    Is there a way to sort the records of a table physically?
    The order by clause does a logical sort on the table data that is temporary.
    Can we sort the records permanently?

    In my environment your query is using a [ INDEX FAST FULL SCAN :|http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i52044] which is not guaranteed to follow physical ordering:
    >
    It cannot be used to eliminate a sort operation, because the data is not ordered by the index key. It reads the entire index using multiblock reads, unlike a full index scan, and can be parallelized.
    >
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    SQL>
    SQL> drop table test_iot;
    Table dropped.
    SQL>
    SQL> create table test_iot(sq number primary key, txt varchar2(20))
      2  organization index;
    Table created.
    SQL>
    SQL> insert into test_iot
      2  select rownum , to_char(rownum,'Fm000000')||'#'||dbms_random.random
      3  from dba_objects where rownum < 1001;
    1000 rows created.
    SQL>
    SQL> exec dbms_stats.gather_table_stats(ownname => user, tabname => 'TEST_IOT', cascade => TRUE);
    PL/SQL procedure successfully completed.
    SQL>
    SQL> explain plan for select * from test_iot;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2167072184
    | Id  | Operation          | Name           | Rows  | Bytes | Cost (%CPU)| Time      |
    |   0 | SELECT STATEMENT     |                |  1000 | 21000 |     3   (0)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| SYS_IOT_TOP_52896 |  1000 | 21000 |     3   (0)| 00:00:01 |
    8 rows selected.Since DBMS_ROWID cannot be used on a IOT, I'm not sure that a SQL query can prove that IOT guarantees physical ordering.

  • Problem with pl/sql table data type

    hai friends,
    i have one procedure it has some in parameters and one out parameter which fetches values to front end.
    But the out parameter will be pl/sql table data type.
    if it is ref cursor
    then i declared as
    var x refcursor;
    exec procedure_name(1,:x);
    it is ok.
    but for pl/sql table data type is out parameter then what i will do in the prompt .
    give me syntax and clarify my doubt.
    advanced thanks...
    madhava

    The SQL*Plus VARIABLE statement does not support user-defined types, hence it cannot support nested tables. It can support cursors because they can be weakly typed (so we can use the one SQL*Plus VAR to hold any shape of resultset). Nested tables are strongly typed; SQL*Plus is a relatively stupid interface and cannot be expected to understand UDT.
    So, it you want to use nested tables as output you'll need to code a wrapping procedure that can understand your nested table type and handle it accordingly.
    Sorry.
    Cheers, APC

  • Problem in printing internal table data in Sapscript!

    Hi All,
    Am trying to print internal table data into main window of sapscript.
    This is what I have written.
    loop at it_final INTO wa_final.
                  CALL FUNCTION 'WRITE_FORM'
                   EXPORTING
                     window   = 'MAIN'
                     ELEMENT  = '670'
                     TYPE     = 'BODY'
                     FUNCTION = 'APPEND'
                   EXCEPTIONS
                     window  = 1
                     element = 2.
                 IF sy-subrc <> 0.
                 ENDIF.
    ENDLOOP.
    IN Sapscript :
    /E   670
    IT     &wa_final-vbeln&,,&wa_final-vbelv&,,&wa_final-payment&
    =      &wa_final-rundate&,,&wa_final-waers&,,&wa_final-creditcard&
    =      &wa_final-augru&,,&wa_final-dmbtr&
    Pls let me know if am missing anything.
    Thanks & Regards
    Himayat

    Check if your Programm is called at the Sapscript level.
    Are you calling the programm from the Sapscript using the PERFORM command? or are these Programm and Sapscript set in customizing?
    Using SE16 check the Message Type and see if Sapscript and the programm are connected at all.

  • Problem in sorting of table

    Hi Friends:
        Below are the records in my table:
    a...|b|c...... |d.....|e................|f
    100||25000|......|0000012998|0002259999
    100|*|25000|1405|0000012998|0002251405
    100|*|25000|1406|0000012998|0002251406
    100|*|25000|1407|0000012998|0002251407
    100|*|25000|1409|0000012998|0002251409
    100|*|25000|1410|0000012998|0002251410
    100|*|25000|1411|0000012998|0002251411
    100|*|25000|1419|0000012998|0002251419
    100|*|25000|1420|0000012998|0002251420
    100|*|25000|1421|0000012998|0002251421
    a = client
    b=  Leg.Dept Code
    c= Legacy Product
    d= Legacy Location
    e= Cost Center
    f= Profit Center
    Please consider '.' as space.
    The problem arises in the sorting of the table records.  The first record shown in the record set above has the following entry:
    a...|b|c...... |d.....|e................|f
    100||25000|......|0000012998|0002259999
    This is the default entry that is to be used if there is no Leg.Location (where Leg. Location = *).  If there is an entry for the specific Leg. Location, then it should be used prior to using this record.
    Problem appears to be that the ABAP program locates this default record prior to encountering the specific record, for example:
    a...|b|c...... |d.....|e................|f
    100|*|25000|1419|0000012998|0002251419
    Because the program encounters the wildcard one first, even if the Leg. Location that the program is searching for is 1419 (which appears in the table, just lower in the listing) the program returns a Profit Center of 2259999 instead of the correct value of 2251419.
    Is it possible to change the native sort of this table so that the wildcard entries appear at the bottom of the listing instead of the top? If yes, can it be done permanently.
    This would allow the program to encounter the specific entries prior to encountering the wildcard ones.

    Hi Paul:
       Thanks for your response. Can you please look at the code below. Actually I've got this issue in the form of a ticket.
    FORM resolve_product_code TABLES pt_accntmap TYPE gtty_accntmap
                               USING p_structraw TYPE gty_structraw.
      DATA: lwa_structraw TYPE gty_structraw,
            lwa_accntmap TYPE gty_accntmap,
            lt_accntmap TYPE gtty_accntmap.
      MOVE  p_structraw              TO  lwa_structraw.
      lt_accntmap[] = pt_accntmap[].
      LOOP AT lt_accntmap INTO lwa_accntmap.
        CLEAR: lwa_accntmap-accntcompstr,
               lwa_accntmap-fndtype,
               lwa_accntmap-posi2.
        IF lwa_accntmap-z_product CA '*_'.
          TRANSLATE lwa_accntmap-z_product USING '_+'.
         SEARCH lwa_structraw-proddiv FOR lwa_accntmap-z_product.
          IF lwa_structraw-proddiv CP lwa_accntmap-z_product.
          IF sy-subrc EQ 0.
            lwa_accntmap-accntcompstr = lwa_structraw-proddiv.
            lwa_accntmap-fndtype      = '*'.
            lwa_accntmap-posi2        = sy-fdpos.
          ENDIF.
        ELSE.
        Must be a full match to win
          IF lwa_structraw-proddiv EQ lwa_accntmap-z_product.
            lwa_accntmap-accntcompstr = lwa_structraw-proddiv.
            lwa_accntmap-fndtype      = space.
            lwa_accntmap-posi2        = 6.
          ENDIF.
        ENDIF.
        MODIFY lt_accntmap FROM lwa_accntmap
             TRANSPORTING accntcompstr fndtype posi2.
      ENDLOOP.
      IF sy-subrc EQ 0.
      Remove any unresolved entries based on Natural Account Code
        DELETE lt_accntmap WHERE  accntcompstr NE lwa_structraw-proddiv.
      ENDIF.
      pt_accntmap[] = lt_accntmap[].
    ENDFORM.                    " resolve_product_code
    Can you please help me with the exact problem in this code.Or if you can give me some idea. It would be a great help.

  • Problem in sorting Advanced Table

    Hi,
    I unable to sort the data in advanced table.The data in the table is populated from an external LOV.When i set the initial sort sequence attribute of the sortable column of the table it is sorting in desecnding order by default.How to sort the data in the ascending order.Please help me it is very urgent.
    Thanks in advance
    Regards
    Srikanth

    The sorting on the table is done by adding the order by clauase and then re querying the vo.
    However here the data is coming from an LOV not from VO.
    Hence what you need to do is add the order by clause to the VO of the multiselect LOV.
    By making the LOV columns sortable (OR ASCENDING BY DEFAULT) and then sorting them in ascending order, see what comes to the base page?..
    IF sorting on lov does not suffices and the need is to provide sorting on the base table is also needed then my suggestion is to associate the same vo of the lov with the advanced table (or put the same query of the lov vo for the advanced table vo)

  • Problem in sorting advacned table attribute

    Hello everyone,
    Would anyone please help me to sort the column of advanced table becoz I need readonly type columns but when I sort in converts into writeable format...
    thanks in advance

    Hi,
    In coloumnHeaderPrompt ther is one property ;Sort All and Initila Staus set them,,,
    wht is the style of the columns in AdvancE Table RN...? IF u want only read only make it to "MessageStyledText"
    Nani
    Edited by: Nani652595 on Feb 24, 2010 10:06 PM

  • Problem while Exporting Table Data to Excel Sheet

    Hi All,
    Im getting problem while downloading the table data to Excel.
    Steps i was fallowed:
    1)created Context node with four attributs.
    2)created one attribut(resource) type:  com.sap.ide.webdynpro.uielementdefinitions.Resource
    3)Taken one Filedownload UI and Property resource bounded to (resource)
    4)Added required jar file in the library and copied the same jar file in the navigator lib file
    written the necessary coding but showing the below  problem in the Browser
    You must Flush before accessing the resource content
    Please give me any suggestion  on this
    Regards
    Polaka

    Hi
    Check this might help with Brian Fernandes comments.
    Flush?
    Regards
    Arun Jaiswal

  • Dynamic Sort on table control

    Hi friends,
    I am having a problem when sorting the table control dynamically based on the fields selectd.
    sorting is not working, when you select multiple fields ( one numeric field and one character field )  I have written code for handling multiple field sort,gettting field names correctly, everything looks fine but internal table is not getting sorted.
    Is it related unicode issue..?
    Any help will be appreciated.
    Sample code:
    loop at tc_control into lc_cols.
      case lc_cols-selected.
             wehn 'X'.
        split lc_cols-screen-name at '-' into gv_tabname gv_fieldname.
        move gv_fieldname gs_struc+lv_off(20)
        add 20 to lv_off.
      endcase.
    endloop.
    if ok_code = 'ASCE'.
      sort itab by (gs_struc-field1) (gs_struc-field2) ..... ascending
    endif.
    Thanks in advance
    Thiru.p

    Hi
    Try using an internal table for the field names..
    Example
    DATA: BEGIN OF ITAB OCCURS 0,
            MATNR TYPE MATNR,
            WERKS TYPE WERKS_D,
          END OF ITAB.
    DATA: ITAB_FIELD(30) OCCURS 0 WITH HEADER LINE.
    DATA
    ITAB-MATNR = 'ABC'.
    ITAB-WERKS = 'ABCD'.
    APPEND ITAB.
    ITAB-MATNR = 'ABC'.
    ITAB-WERKS = 'ABC'.
    APPEND ITAB.
    SORT INTERNAL TABLE
    ITAB_FIELD = 'MATNR'.
    <b>APPEND ITAB_FIELD.</b>
    ITAB_FIELD = 'WERKS'.
    <b>APPEND ITAB_FIELD.</b>
    <b>SORT ITAB BY (ITAB_FIELD).</b>
    LOOP AT ITAB.
      WRITE: / ITAB-MATNR,ITAB-WERKS.
    ENDLOOP.
    Thanks
    Naren

  • Sorting WD table

    Hi all,
    I have a small problem with sorting WD tables.
    I have java bean model as datasource for table. In this bean, I have non-string attributes like date, etc. I want to format them, so I've added additional String attribute for every attribute I want to format.
    When i'm click to sort (I use standard TableSorter) by some of additional String attribute (column with original attr. is invisible and I put that invisible column name to sortBy method to achieve correct sorting behaviour), I lost ascending/descending icon on that substituted column...
    Have somebody solution for this?
    Best Regards,
    Michal

    Hi,
    If not how can I turn off sorting on such a columns.
    As far, there is no such provision for table columns!. However in ALV, you can use IF_SALV_WD_SORT~SET_SORT_ALLOWED method to set sort on/off for ALV column.
    Regards,
    Kiran

  • Sorting the table

    Dear Guru's
      Can you please advice me how I can sort the table data in Adobe Interactive form.
    Thanks!
    Surya.

    Hi,
    In the context area , Double click on the table.
    In the bottom area u can see the properties tab....
    In that go to control levels tab where u cna set the sorting on the basis of a particular field.
    Please let me know if you find any issue.
    Regards,
    sasi

  • Problem in capturing the edited data while the table is sorted

    hi,
    i am using the TableSorter class provided by the sun tutorials to add sorting capability for my JTable. i need to print on the screen, the value of the cell whenever it is updated. so i am using TableModelListener and its tableChanged() method for this purpose. if i edit the data without applying the sorting then its printing fine. But if i edit the data with table sorted in a particular order by clicking on the table header then the tableChanged method is not being called. So some problem lies in the table sorter which is preventing the call to the tableChanged method whenver table it is sorted. Below is my implementation of JTable.
    TableSorter sorter = new TableSorter(new MyTableModel());
    final JTable table = new JTable(sorter);
    table.getModel().addTableModelListener(new
    TableModelListener()
         public void tableChanged(TableModelEvent e)
              int row = e.getFirstRow();
                                               int column = e.getColumn();
              System.out.println("Row: "+row+" Coloumn:  "+column);
    );Hope u understood the problem. plzz help
    thanx

    hi camickr,
    However the row number displayed is always the row of
    the TableModel before the data has been sorted. this is the feature i am trying for and couldnt achieve it. i do want to print the row of tablemodel before data is sorted but i am getting 0 and -1 as row and column numbers.
    I never saw -1 as a column number.
    if you have never seen -1 as column number then just compile and run the code given below. I just added a table model listener to the table model to capture data editing. So if u edit any cell without applying sorting then its row and column number is printed properly but if u sort a particlar column and with sorting on if u edit any cell you will get row No. as 0 and column No. as -1. try running below code and please let me know where the problem exists or post your code which worked without any of the above problems.
    I believe the code was updated in Feb of this year,
    so make sure you have the most recent version.yes i have the latest version of tablesorter.
    below is my source code for table sorting just compile and run it
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.sql.*;
    import javax.swing.table.*;
    import java.util.*;
    class TableSorterDemo extends JFrame
         public TableSorterDemo()
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         TableSorter sorter=new TableSorter(new MyTableModel());
         JTable table=new JTable(sorter);
         sorter.setTableHeader(table.getTableHeader());
         table.getModel().addTableModelListener(new
    TableModelListener()
         public void tableChanged(TableModelEvent e)
              int row = e.getFirstRow();
            int column = e.getColumn();
              System.out.println("Row :"+row+" Column: "+column);
         JScrollPane scrollPane = new JScrollPane(table);
         scrollPane.setBackground(new Color(198,232,189));
         add(scrollPane);
         pack();
         setVisible(true);
          class MyTableModel extends AbstractTableModel {
            final String[] columnNames = {"First Name",
                                          "Last Name",
                                          "Sport",
                                          "# of Years",
                                          "Vegetarian"};
            final Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Chasing toddlers", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Angela", "Lih",
                 "Teaching high school", new Integer(4), new Boolean(false)}
            public int getColumnCount() {
                return columnNames.length;
            public int getRowCount() {
                return data.length;
            public String getColumnName(int col) {
                return columnNames[col];
            public Object getValueAt(int row, int col) {
                return data[row][col];
             * JTable uses this method to determine the default renderer/
             * editor for each cell.  If we didn't implement this method,
             * then the last column would contain text ("true"/"false"),
             * rather than a check box.
            public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
             * Don't need to implement this method unless your table's
             * editable.
            public boolean isCellEditable(int row, int col) {
                //Note that the data/cell address is constant,
                //no matter where the cell appears onscreen.
                if (col < 2) {
                    return false;
                } else {
                    return true;
             * Don't need to implement this method unless your table's
             * data can change.
            public void setValueAt(Object value, int row, int col) {
                    data[row][col] = value;
                    fireTableCellUpdated(row, col);
                   //     System.out.println("row "+row+"Col "+col+"Val "+value);
         public static void main(String[] args)
         new TableSorterDemo();
       /*Table Sorter Class*/
    class TableSorter extends AbstractTableModel {
        protected TableModel tableModel;
        public static final int DESCENDING = -1;
        public static final int NOT_SORTED = 0;
        public static final int ASCENDING = 1;
        private static Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);
        public static final Comparator COMPARABLE_COMAPRATOR = new Comparator() {
            public int compare(Object o1, Object o2) {
                return ((Comparable) o1).compareTo(o2);
        public static final Comparator LEXICAL_COMPARATOR = new Comparator() {
            public int compare(Object o1, Object o2) {
                return o1.toString().compareTo(o2.toString());
        private Row[] viewToModel;
        private int[] modelToView;
        private JTableHeader tableHeader;
        private MouseListener mouseListener;
        private TableModelListener tableModelListener;
        private Map columnComparators = new HashMap();
        private java.util.List sortingColumns = new ArrayList();
        public TableSorter() {
            this.mouseListener = new MouseHandler();
            this.tableModelListener = new TableModelHandler();
        public TableSorter(TableModel tableModel) {
            this();
            setTableModel(tableModel);
        public TableSorter(TableModel tableModel, JTableHeader tableHeader) {
            this();
            setTableHeader(tableHeader);
            setTableModel(tableModel);
        private void clearSortingState() {
            viewToModel = null;
            modelToView = null;
        public TableModel getTableModel() {
            return tableModel;
        public void setTableModel(TableModel tableModel) {
            if (this.tableModel != null) {
                this.tableModel.removeTableModelListener(tableModelListener);
            this.tableModel = tableModel;
            if (this.tableModel != null) {
                this.tableModel.addTableModelListener(tableModelListener);
            clearSortingState();
            fireTableStructureChanged();
        public JTableHeader getTableHeader() {
            return tableHeader;
        public void setTableHeader(JTableHeader tableHeader) {
            if (this.tableHeader != null) {
                this.tableHeader.removeMouseListener(mouseListener);
                TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
                if (defaultRenderer instanceof SortableHeaderRenderer) {
                    this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
            this.tableHeader = tableHeader;
            if (this.tableHeader != null) {
                this.tableHeader.addMouseListener(mouseListener);
                this.tableHeader.setDefaultRenderer(
                        new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
        public boolean isSorting() {
            return sortingColumns.size() != 0;
        private Directive getDirective(int column) {
            for (int i = 0; i < sortingColumns.size(); i++) {
                Directive directive = (Directive)sortingColumns.get(i);
                if (directive.column == column) {
                    return directive;
            return EMPTY_DIRECTIVE;
        public int getSortingStatus(int column) {
            return getDirective(column).direction;
        private void sortingStatusChanged() {
            clearSortingState();
            fireTableDataChanged();
            if (tableHeader != null) {
                tableHeader.repaint();
        public void setSortingStatus(int column, int status) {
            Directive directive = getDirective(column);
            if (directive != EMPTY_DIRECTIVE) {
                sortingColumns.remove(directive);
            if (status != NOT_SORTED) {
                sortingColumns.add(new Directive(column, status));
            sortingStatusChanged();
        protected Icon getHeaderRendererIcon(int column, int size) {
            Directive directive = getDirective(column);
            if (directive == EMPTY_DIRECTIVE) {
                return null;
            return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
        private void cancelSorting() {
            sortingColumns.clear();
            sortingStatusChanged();
        public void setColumnComparator(Class type, Comparator comparator) {
            if (comparator == null) {
                columnComparators.remove(type);
            } else {
                columnComparators.put(type, comparator);
        protected Comparator getComparator(int column) {
            Class columnType = tableModel.getColumnClass(column);
            Comparator comparator = (Comparator) columnComparators.get(columnType);
            if (comparator != null) {
                return comparator;
            if (Comparable.class.isAssignableFrom(columnType)) {
                return COMPARABLE_COMAPRATOR;
            return LEXICAL_COMPARATOR;
        private Row[] getViewToModel() {
            if (viewToModel == null) {
                int tableModelRowCount = tableModel.getRowCount();
                viewToModel = new Row[tableModelRowCount];
                for (int row = 0; row < tableModelRowCount; row++) {
                    viewToModel[row] = new Row(row);
                if (isSorting()) {
                    Arrays.sort(viewToModel);
            return viewToModel;
        public int modelIndex(int viewIndex) {
            return getViewToModel()[viewIndex].modelIndex;
        private int[] getModelToView() {
            if (modelToView == null) {
                int n = getViewToModel().length;
                modelToView = new int[n];
                for (int i = 0; i < n; i++) {
                    modelToView[modelIndex(i)] = i;
            return modelToView;
        // TableModel interface methods
        public int getRowCount() {
            return (tableModel == null) ? 0 : tableModel.getRowCount();
        public int getColumnCount() {
            return (tableModel == null) ? 0 : tableModel.getColumnCount();
        public String getColumnName(int column) {
            return tableModel.getColumnName(column);
        public Class getColumnClass(int column) {
            return tableModel.getColumnClass(column);
        public boolean isCellEditable(int row, int column) {
            return tableModel.isCellEditable(modelIndex(row), column);
        public Object getValueAt(int row, int column) {
            return tableModel.getValueAt(modelIndex(row), column);
        public void setValueAt(Object aValue, int row, int column) {
            tableModel.setValueAt(aValue, modelIndex(row), column);
        // Helper classes
        private class Row implements Comparable {
            private int modelIndex;
            public Row(int index) {
                this.modelIndex = index;
            public int compareTo(Object o) {
                int row1 = modelIndex;
                int row2 = ((Row) o).modelIndex;
                for (Iterator it = sortingColumns.iterator(); it.hasNext();) {
                    Directive directive = (Directive) it.next();
                    int column = directive.column;
                    Object o1 = tableModel.getValueAt(row1, column);
                    Object o2 = tableModel.getValueAt(row2, column);
                    int comparison = 0;
                    // Define null less than everything, except null.
                    if (o1 == null && o2 == null) {
                        comparison = 0;
                    } else if (o1 == null) {
                        comparison = -1;
                    } else if (o2 == null) {
                        comparison = 1;
                    } else {
                        comparison = getComparator(column).compare(o1, o2);
                    if (comparison != 0) {
                        return directive.direction == DESCENDING ? -comparison : comparison;
                return 0;
        private class TableModelHandler implements TableModelListener {
            public void tableChanged(TableModelEvent e) {
                // If we're not sorting by anything, just pass the event along.            
                if (!isSorting()) {
                    clearSortingState();
                    fireTableChanged(e);
                    return;
                if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                    cancelSorting();
                    fireTableChanged(e);
                    return;
                int column = e.getColumn();
                if (e.getFirstRow() == e.getLastRow()
                        && column != TableModelEvent.ALL_COLUMNS
                        && getSortingStatus(column) == NOT_SORTED
                        && modelToView != null) {
                    int viewIndex = getModelToView()[e.getFirstRow()];
                    fireTableChanged(new TableModelEvent(TableSorter.this,
                                                         viewIndex, viewIndex,
                                                         column, e.getType()));
                    return;
                // Something has happened to the data that may have invalidated the row order.
                clearSortingState();
                fireTableDataChanged();
                return;
        private class MouseHandler extends MouseAdapter {
            public void mouseClicked(MouseEvent e) {
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                int column = columnModel.getColumn(viewColumn).getModelIndex();
                if (column != -1) {
                    int status = getSortingStatus(column);
                    if (!e.isControlDown()) {
                        cancelSorting();
                    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                    status = status + (e.isShiftDown() ? -1 : 1);
                    status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                    setSortingStatus(column, status);
        private static class Arrow implements Icon {
            private boolean descending;
            private int size;
            private int priority;
            public Arrow(boolean descending, int size, int priority) {
                this.descending = descending;
                this.size = size;
                this.priority = priority;
            public void paintIcon(Component c, Graphics g, int x, int y) {
                Color color = c == null ? Color.GRAY : c.getBackground();            
                // In a compound sort, make each succesive triangle 20%
                // smaller than the previous one.
                int dx = (int)(size/2*Math.pow(0.8, priority));
                int dy = descending ? dx : -dx;
                // Align icon (roughly) with font baseline.
                y = y + 5*size/6 + (descending ? -dy : 0);
                int shift = descending ? 1 : -1;
                g.translate(x, y);
                // Right diagonal.
                g.setColor(color.darker());
                g.drawLine(dx / 2, dy, 0, 0);
                g.drawLine(dx / 2, dy + shift, 0, shift);
                // Left diagonal.
                g.setColor(color.brighter());
                g.drawLine(dx / 2, dy, dx, 0);
                g.drawLine(dx / 2, dy + shift, dx, shift);
                // Horizontal line.
                if (descending) {
                    g.setColor(color.darker().darker());
                } else {
                    g.setColor(color.brighter().brighter());
                g.drawLine(dx, 0, 0, 0);
                g.setColor(color);
                g.translate(-x, -y);
            public int getIconWidth() {
                return size;
            public int getIconHeight() {
                return size;
        private class SortableHeaderRenderer implements TableCellRenderer {
            private TableCellRenderer tableCellRenderer;
            public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) {
                this.tableCellRenderer = tableCellRenderer;
            public Component getTableCellRendererComponent(JTable table,
                                                           Object value,
                                                           boolean isSelected,
                                                           boolean hasFocus,
                                                           int row,
                                                           int column) {
                Component c = tableCellRenderer.getTableCellRendererComponent(table,
                        value, isSelected, hasFocus, row, column);
                if (c instanceof JLabel) {
                    JLabel l = (JLabel) c;
                    l.setHorizontalTextPosition(JLabel.LEFT);
                    int modelColumn = table.convertColumnIndexToModel(column);
                    l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
                return c;
        private static class Directive {
            private int column;
            private int direction;
            public Directive(int column, int direction) {
                this.column = column;
                this.direction = direction;
    }

  • How to re-sort Table data like A-Z and Z-A

    Hello Gurus,
      How can i re-sort Table data based on last name or first name, once table filled data from backend(i mean, once executed RFC,  Table will be filled with data records, after that i want to re-sort table).
       Can you provide me code, how to do?
    Thanks
    Venkat.

    Hi Venkat,
    For sorting to table columns, you need to pick up the code from here and add into a java file within your development component.
    http://wiki.sdn.sap.com/wiki/display/Snippets/TableSorterClassfor+WebDynpro
    Then, you can call the constructor of the class and pass the arguments to enable table sorting in your code.
    Refer to following blog for execution
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417100)ID1078501850DB00490474849923920126End?blog=/pub/wlg/3287
    Let me know, if the problem persists.
    Regards,
    Tushar Sinha

  • Problem with sorting and filtering of table

    Hello,
    using VC 7.1 SP5 I have created [this|http://img232.imageshack.us/img232/2460/screenshotsr0.png] model. The webservice returns a collection of structured elements. The table is meant to display values of top-level attributes. This works as expected.
    However, the table cannot be sorted or filtered. What is the reason for this? How can I fix that?
    I tried to store the result of the web service in a data bridge. That did not succeed.
    Best regards
    Alexander

    Hi Natty,
    How are you trying to sort it?
    I want to be able to sort the table by clicking on the table column headers. Furthermore, I want be able to filter the table by using the built-in table feature. However, table sorting and filtering seem to be disabled for this particular table, whereas other tables in my model provide the desired features.
    Best regards
    Alexander

Maybe you are looking for

  • PI in ECC 6.0, usage type AS ABAP

    Dear all, Is there any restriction on the functionalities of PI/XI in ECC 6.0 (with ABAP only)? Can I have full XI functionalities if when I install ECC 6.0, I also check AS Java? Giang

  • How to access internal hard drive with screen not working

    Veteran Mac user from Spain, I am a graphic designer and i have a MacBook Pro 17 inch Intel Core 2 Duo 2.4 GHz (Santa Rosa) which i purchased in October of 2007 along with a 23 inch Apple Cinema HD Display Monitor which i have hooked up to my MacBook

  • Error "Disk too slow"

    I record on my PB G4, with Garage Band. I run instruments to a board, then to the m-audio fast track. the files are saved on a Seagate 300GB External FireWire Drive, from which i record. I understand it is caused due to the high number of tracks with

  • T-code OITA

    I want to know the significance of AUC per source strucutre,line item settlement and summary settlement in details with examples in tcode oita(in spro).

  • Acrobat Pro 9 Trial Ended Prematurely

    I installed the trial version two days ago.  Now the program has told me my trial has expired.  It was supposed to be a 30-day trial.  I see this problem has been posted with other Adobe programs. Talked and chatted with Adobe Tech to no avail. Is th