Sorting rows by choosen column.

What kind of Array(Map, or any other data structure) should I use, if i want sort all rows by values in j-th column.
Suppose i need to store data like this:
Name | Surname | Telephone
---------| ---------------|--------------
Dawid| Olaf | 3422353
Jack | Ugly | 7872347
Mike | Opis | 38483848
And now i want sort all rows by Surname.
Is there any covenient data structure to make such things ?

Why you asking for ?
I'm simply not familiarize with data structures in java and i thought that there is data structure in java like array, with possibility of sorting rows by choosen column.
I think the only way to do that is use sortAllRowsBy(DefaultTableModel model, int colIndex, boolean ascending).

Similar Messages

  • Sort Rows by Color?

    I have color coded some of the rows for a project I'm working on and would love to sort all the 'colored' rows together. Is there a way to sort by the color that I've chosen to fill each row with?
    When I had only two colors I was using a workaround. I added a check-box column and had one color = a check mark. That allowed me to sort the checkbox column. Now I have four colors and this doesn't work any more.
    Any ideas?

    Quick & dirty solution:
    Add a column with the header marked 'color'
    Then use numeric or text entries: Red, Blue, Green, Black, 1, 2, 3, 4 ... a, b, c, d, or whatever for your color codes in that column.
    Then sort by the 'color' column.
    Now mark the 'color' column as hidden.

  • Sort rows by fill color?

    Is it possible in Numbers to sort rows based on the row fill color? There are only 2 colors the rows have as background (fill), and it would save time to sort based on the highlighted row. Any ideas?
    Thank you-

    I agree with jerrold.
    I will certainly not ask Apple for such a feature.
    Here is a script which may give you an efficient response.
    property columnOffset : 2
    tell application "Numbers"
    activate
    set {rName, tName, sName, dName} to my getSelection()
    if (character 2 of rName) as text > "9" then
    set columnLetter to text 1 thru 2 of rName
    else
    set columnLetter to character 1 of rName
    end if
    set twoNames to my decoupe(rName, ":")
    set {colNum1, rowNum1} to my decipher(item 1 of twoNames)
    set columnToSort to colNum1 + columnOffset
    tell document dName to tell sheet sName to tell table tName
    set myColor to background color of (get properties of range rName)
    set nbRows to count rows
    repeat with r from 1 to 14 --nbRows
    set val to background color of (get properties of range (columnLetter & r & ":" & columnLetter & r))
    set val to (val is myColor)
    set value of cell r of column columnToSort to val
    end repeat
    end tell
    end tell
    --=====
    on getSelection()
    local mySelectedRanges, sheetRanges, thisRange, _, myRange, myTable, mySheet, myDoc, mySelection
    tell application "Numbers"
    activate
    tell document 1
    set mySelectedRanges to selection range of every table of every sheet
    repeat with sheetRanges in mySelectedRanges
    repeat with thisRange in sheetRanges
    if contents of thisRange is not missing value then
    try
    --return thisRange --poorly formed result
    thisRange as text
    on error errMsg number errNum
    set {_, myRange, _, myTable, _, mySheet, _, myDoc} to my decoupe(errMsg, quote)
    --set mySelection to (a reference to (range rn of table tn of sheet sn))
    return {myRange, myTable, mySheet, myDoc}
    end try
    end if -- contents…
    end repeat -- thisRange
    end repeat -- sheetRanges
    end tell -- document 1
    end tell -- application
    return {missing value, missing value, missing value, missing value}
    end getSelection
    --=====
    on decipher(n)
    local letters, colNum, rowNum
    set letters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    if (character 2 of n) as text > "9" then
    set colNum to (offset of (character 1 of n) in letters) * 64 + (offset of (character 2 of n) in letters)
    set rowNum to (text 3 thru -1 of n) as integer
    else
    set colNum to offset of (character 1 of n) in letters
    set rowNum to (text 2 thru -1 of n) as integer
    end if
    return {colNum, rowNum}
    end decipher
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d
    set l to text items of t
    set AppleScript's text item delimiters to ""
    return l
    end decoupe
    --=====
    Select a cell with the color to use in the sort.
    Run the script.
    It will fill the column whose offset from the selected one is defined by the property 'columnOffset'
    If the background of the cell in the source column is the searched one the value will be 1
    if the background is not this one, the value will be 0.
    So it will be easy to use a condition.
    Yvan KOENIG (from FRANCE mardi 10 mars 2009 20:39:44)

  • MS Query...cannot write sorted rows error

    I have an MS Query report crated and it was working well until i tried to remove a Criteria Filter within the query. I get an error "Cannot Write Sorted Row". If I acknowledge the error, the change to the criteria is not saved and it reverts to
    the original setting. I had several columns sorted, of which i deleted the SQL code for sort thinking that may help. I also tried to delete the Criteria Filter via the wizard and directly in SQL but that did not help.
    Any suggestions of what may be the issue?

    This is a Power Query forum and so it's unlikely you'll find MS Query experts here. That being said, did you try using Power Query for your scenario?

  • How to transpose rows into multiple columns using pivot table

    I have 1 row containing 12 columns with value "JAN", "FEB", "MAR", "J-1","F-1","M-1","J-2","F-2","M-2","J-3","F-3","M-3"
    I want to display as
    JAN J-1 F-1 M-1
    FEB J-2 F-2 M-2
    MAR J-3 F-3 M-3
    How do I achieve the above?

    Today you have only 3 months JAN, FEB, MAR. Is it always the same number of columns. What if there are more months added to this row?
    Is your data really coming from relational source or some sort of text file?
    There is a better way to do this in narrative view using HTML if your requirement is just to show them in multiple rows and do some calculations.
    Go to Narrative View;
    In prefix, use <html> <table>
    In 'Narrative' text box add something like this
    <tr> <td> @1 </td> <td> @4 </td> <td> @7 </td> </tr>
    <tr> <td> @2 </td> <td> @5 </td> <td> @8 </td> </tr>
    <tr> <td> @3 </td> <td> @6 </td> <td> @9 </td> </tr>
    In Suffix, use </table> </html>
    You can also add simple calculations like sum etc at the very bottom of these rows as grand totals.
    kris

  • Sort rows in JTable except the last row

    Hi All,
    I have a JTable, which contains columns with numbers. The last row contains column sums.
    I want to be able to sort rows, but the last row with sums must remain motionless.
    Does anyone know the solution of this problem?
    Thanks in advance.

    These two posts are my example. It works pretty good but there is one significant niggle - when moving a column the 'total' table does not move smoothly but it does move. I look forward to 'camickr' reducing this to about 1 line.
    Part A.
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Font;
    import java.text.DecimalFormat;
    import java.util.Comparator;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.TableColumnModelEvent;
    import javax.swing.event.TableColumnModelListener;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableColumnModel;
    import javax.swing.table.TableModel;
    import javax.swing.table.TableRowSorter;
    public class Sabre20090331
        static private class TotalizingTableComponent extends JScrollPane
            private TotalizingTableComponent(final TableModel tableModel)
                final SecondaryTableModel secondaryTableModel = new SecondaryTableModel(tableModel);
                final JTable secondaryTable = new JTable(secondaryTableModel);
                for (int i = 1; i < secondaryTableModel.getColumnCount(); i++)
                    secondaryTable.getColumnModel().getColumn(i).setCellRenderer(new NumberCellRenderer());
                secondaryTable.getColumnModel().getColumn(0).setCellRenderer(new TitleCellRenderer());
                final TableColumnModel secondaryTableColumnModel = secondaryTable.getColumnModel();
                secondaryTable.setRowSelectionAllowed(false);
                final JTable primaryTable = new JTable(tableModel);
                for (int i = 1; i < tableModel.getColumnCount(); i++)
                    primaryTable.getColumnModel().getColumn(i).setCellRenderer(new NumberCellRenderer());
                final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
                final DoubleComparator doubleComparator = new DoubleComparator();
                for (int i = 1; i < tableModel.getColumnCount(); i++)
                    sorter.setComparator(i, doubleComparator);
                primaryTable.setRowSorter(sorter);
                primaryTable.getColumnModel().addColumnModelListener(new TableColumnModelListener()
                    @Override
                    public void columnAdded(TableColumnModelEvent e)
                        // System.out.println("columnAdded()" + e);
                    @Override
                    public void columnRemoved(TableColumnModelEvent e)
                        // System.out.println("columnRemoved()" + e);
                    @Override
                    public void columnMoved(TableColumnModelEvent e)
                        //System.out.println("columnMoved()" + e);
                        secondaryTableColumnModel.moveColumn(e.getFromIndex(), e.getToIndex());
                    @Override
                    public void columnMarginChanged(ChangeEvent e)
                        //System.out.println("columnMarginChanged()" + e);
                        final TableColumnModel cm = (TableColumnModel) e.getSource();
                        for (int i = 0; i < cm.getColumnCount(); i++)
                            secondaryTableColumnModel.getColumn(i).setPreferredWidth(cm.getColumn(i).getWidth());
                    @Override
                    public void columnSelectionChanged(ListSelectionEvent e)
                        //System.out.println("columnSelectionChanged()" + e);
                final JTableHeader primaryHeader = primaryTable.getTableHeader();
                JPanel inner = new JPanel(new BorderLayout());
                this.setColumnHeaderView(primaryHeader);
                this.setViewportView(inner);
                inner.add(primaryTable, BorderLayout.NORTH);
                inner.add(secondaryTable, BorderLayout.CENTER);
            public static void main(String[] args)
                final JFrame frame = new JFrame("Totalizing JTable Example");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                final TableModel tableModel = new PrimaryTableModel();
                frame.setContentPane(new TotalizingTableComponent(tableModel));
                frame.pack();
                frame.setVisible(true);
    }Edited by: sabre150 on Apr 1, 2009 9:21 AM
    Changed the layout of the inner panel so that the secondary table is now in the CENTER. This stops the secondary table becoming detached from the primary when one expands the frame beyond the prefferred size.

  • How to get multiple records in one row and different column

    Hi All,
    I am using oracle database 11g
    and i have a two tables table_1, table_2
    table_1 having columns
    emp_no
    first_name
    middle_name
    last_name
    email
    and table_2 having columns
    emp_no
    phone_type
    phone_number
    and having entires
    emp_no phone_type phone_number
    1001 MOB 9451421452
    1001 WEMG 235153654
    1001 EMG 652341536
    1002 MOB 9987526312
    1003 WEMG 5332621456
    1004 EMG 59612356
    Now i want the output of values with phone type as MOB or WEMG in a single row with different columns
    emp_no first_name middle_name last_name email mobile officeno
    1001 mark null k [email protected] 9451421452 235153654
    1002 john cena gary [email protected] 9987526312 null
    1003 dany null craig [email protected] null 5332621456
    1004 donald finn sian [email protected] null null
    can i have any inputs to achive this???
    Regards
    $sid

    Frank Kulash wrote:
    sonething like this:Frank, you missed aggregate function (pivot requires one). However main thing is it will cause ORA-01748:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k'last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
    SELECT     *
    FROM     table_1      t1
    JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    PIVOT     (    max(t2.phone_number)
         FOR  t2.phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
            FOR  t2.phone_type  IN  ( 'MOB'   AS mob
    ERROR at line 19:
    ORA-01748: only simple column names allowed hereYou need to:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k' last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
         table_3 as (
                     select  t1.emp_no,first_name,middle_name,last_name,email,
                             phone_type,phone_number
                       FROM     table_1      t1
                       LEFT JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    SELECT     *
    FROM     table_3
    PIVOT     (    max(phone_number)
         FOR  phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
        EMP_NO FIRST_ MIDD LAST_ EMAIL                     MOB       WEMG
          1004 donald finn sian  [email protected]
          1003 dany        craig [email protected] null            5332621456
          1001 mark        k     [email protected]      9451421452  235153654
          1002 john   cena gary  [email protected]    9987526312
    SQL>SY.

  • Converting each row in a column to an XML

    Hi everyone,
    Using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
    I have a table where there is a comments column which is VARCHAR2. That column contains string data in the form of XML tags.
    Like for eg. *<tag_name attr_name="10"/>* (sorry cant provide the exact values as I'm not allowed to)
    There are many such rows. Now I want to use these strings and operate on them as XML like using XPath to find certain attributes etc.
    I tried using the extract function and to use it i need a XMLType object. So I tried to create one using the XMLType() constructor.
    But it gives me the error ORA-19032: Expected XML tag , got no content
    When I looked it up on the net, I found that this error number doesn't correspond to the error message that I'm getting. The error msg found on the internet was Expected XML tag string got string
    I used this query
    SELECT XMLType (<column>) FROM <table>;But when I modified it (based on someone's hunch) to
    SELECT XMLType (<column>)
      FROM <table>
    WHERE ROWNUM <= 1;The query worked fine. Like it can take only one row.
    I also tried like this
    SELECT XMLType ('<tag_name attr_name="10"/>')
      FROM DUAL;This too worked fine.
    So finally this has left me completely confused. Is there a way to convert every row in a column to an XMLType object so that I can use the extract function to gather information about it.
    For the time being I have used REGEXes to write the code. But having the flexibility of xml would be better.
    Any help would be appreciated.
    Regards,
    Arijit
    Edited by: Arijit Kanrar on May 23, 2013 5:27 AM

    Arijit,
    The error message is correct. What you found is merely the generic message with string placeholders.
    The error message is also pretty self-explanatory : you can't pass an empty string (NULL) to the XMLType constructor.
    SQL> select xmltype('') from dual;
    ERROR:
    ORA-19032: Expected XML tag , got no content
    ORA-06512: at "SYS.XMLTYPE", line 310
    ORA-06512: at line 1
    no rows selectedYou have to either add a WHERE clause to filter out NULL columns, or use a CASE statement to only convert strings that aren't empty :
    SELECT XMLType (<column>)
      FROM <table>
    WHERE <column> IS NOT NULL ;
    SELECT CASE WHEN <column> IS NOT NULL THEN XMLType (<column>) END
    FROM ...And do not use EXTRACT if you want to access scalar values, use EXTRACTVALUE instead :
    SQL> select extractvalue(xmltype('<tag_name attr_name="10"/>'), '/tag_name/@attr_name') from dual;
    EXTRACTVALUE(XMLTYPE('<TAG_NAMEATTR_NAME="10"/>'),'/TAG_NAME/@ATTR_NAME')
    10

  • On ALV report in1 column I want to put Icon on every row of that column.

    On ALV report there is 1 column I want to put Icon on every row of that column.That ALV program uses object oriented concept all class and methods.
      I want to use that icon on that row. That icon name is ‘ICON_OKAY’
    In my program when I assign values to internal table at that time I am assigning that ‘ICON_OKAY’ value to that row as follow.
    Itab-
    Itab-icon = ICON_OKAY.
    Append itab.

    please follow below procedure to display icon in ALV
    1) In corresponding fieldcatelog entry do
    fieldcatalog-icon = 'X'
    2) While filling the internal table fill the corresponding key value of icon , for example ICON_OKAY value is '@0V@' so statement would be
    Itab-icon = '@0V@'
    to get list of corresponding key for icon open include <ICON> in se38

  • Different number of rows for different columns in JTable

    hi
    I need to create a JTable with different number of rows for different columns...
    Also the rowheight should be different in each column...
    say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
    The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
    how do I do this ??
    can anybody send me some sample code ?????
    thanx in advance

    How about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
    Or you could leave the extra columns null/blank.
    You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
    It would help if you were more specific about how you wanted it to appear and behave.

  • How to get fourthly row (row4) first column value (col1) in matrix

    Hi to all,
    In FMS, how to get fourthly row (row4) first column value (col1) in matrix in document.
    select $[$38.1.4]
    But it display the first row
    Please give me hint.
    Thank you

    Hi Eric,
    FMS may only apply to current row.  There is no way to get any other fixed row.
    Thanks,
    Gordon

  • Applying table scroll bar for only table rows with table columns fixed.

    hi oa gurus,
    i had implemented table scroll bars using oarawtextbean , there is no problem in vertical and horizontal scroll bar working its working fine. but the requirement is i need to scroll only the table rows with table columns fixed. so , how to achieve the table scroll for only table datas neglecting table headers.
    the code for vertical and horizontal bars scroll is like this,
    OARawTextBean ors = (OARawTextBean)webBean.findChildRecursive("raw1");
    ors.setText(div id=tabledivid style=height:500px;width:100%; overflow:auto>);
    OARawTextBean ore = (OARawTextBean)webBean.findChildRecursive("raw2");
    ore.setText("</div>");
    where raw1 and raw2 are rawtextbean created above and below of the table . but i dont know hoow to apply this only for table rows neglecting table columns , can anybody give any ideas.
    pelase this is very urgent , can u help me in this regards
    thanks
    Edited by: user630121 on Sep 29, 2008 5:17 AM
    Edited by: user630121 on Sep 29, 2008 5:18 AM

    hi,
    I have a similar task to do... Only to apply scrollbar at the table level.
    I tried using the above mentioned but I am facing Null Pointer Exception..
    Please explain about raw1 and raw2
    Rahul

  • Count the no. of rows in a column

    I want to count the no. of rows in APR_QTY column that are not equal to zero.
    SELECT DISTINCT
    SUPP_NAME,
    ITEM_NAME,
    (CASE WHEN BH_CAL_PERIOD=4 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)APR_QTY,
    (CASE WHEN BH_CAL_PERIOD=4 THEN BI_RATE ELSE 0 END)APR_RATE,
    (CASE WHEN BH_CAL_PERIOD=5 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)MAY_QTY,
    (CASE WHEN BH_CAL_PERIOD=5 THEN BI_RATE ELSE 0 END)MAY_RATE,
    (CASE WHEN BH_CAL_PERIOD=6 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUNE_QTY,
    (CASE WHEN BH_CAL_PERIOD=6 THEN BI_RATE ELSE 0 END)JUNE_RATE,
    (CASE WHEN BH_CAL_PERIOD=7 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUL_QTY,
    (CASE WHEN BH_CAL_PERIOD=7 THEN BI_RATE ELSE 0 END)JUL_RATE
    FROM
    OM_SUPPLIER,
    OM_ITEM,
    OT_BILL_HEAD,
    OT_BILL_ITEM,
    OT_BILL_ITEM_TED
    WHERE BI_BH_SYS_ID = BH_SYS_ID
    AND SUPP_CODE = BH_SUPP_CODE
    AND ITEM_CODE = BI_ITEM_CODE
    AND BH_SYS_ID = ITED_H_SYS_ID
    AND BI_SYS_ID = ITED_I_SYS_ID
    AND BH_TXN_CODE='SBRLRAW'
    GROUP BY BH_CAL_PERIOD,BH_TXN_CODE,SUPP_NAME,ITEM_NAME,BI_RATE,BI_QTY,BI_QTY_LS
    ORDER BY ITEM_NAME
    Message was edited by:
    yogeshyl

    Select sum(decode(apr_qty,0,0,1)) as cnt_apr_qty
    from ...

  • How can we fix images and String in a perticular row's second column in JTa

    Hi,
    I have to design a window in which there is a table I have to set the some row's second column data with images and text data both and some row contan only text data Please help me on it .There is two column and 5 row in my table.
    Thanks in advance,
    anum

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender]Using Editors and Renderers
    You will need to create a custom renderer to display both an image and text. Renderers are assigned to a column. If you require different renderers for a given row in a column then you will need to override the getCellRenderer(...) method to return a renderer for the specific row.

  • How to get difference between two rows for a column field?

    hi, all,
    Could anyone show me what query statement is to get the difference betweem two rows for two column fields?
    The tables and its records are like this:
    id,      begin,      end
    p1         21          30
    p2          45          60
    p3          120          150
    I would like to have the query result like this
    id,    diff
    p1     15    --- which is 45 minus 30
    p2     60    --- which is 120 minus 60
    and so on...
    thank you in advance.
    Raffy

    You can use the LAG function to access values from previous rows:
    with q as (select 'p1' id, 21 v_start, 30 v_end from dual
    union all
    select 'p2', 45, 60 from dual
    union all
    select 'p3', 120, 150 from dual)
    select id, v_start, v_end, v_start - lag (v_end, 1, 0)
      over (order by id) v_diff from q
    ID,V_START,V_END,V_DIFF
    p1,21,30,21
    p2,45,60,15
    p3,120,150,60
    See the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions075.htm

Maybe you are looking for

  • Database connection with EJB and  Sun Application Server

    I have tried some tutorials from sun in Savings account eg some errors were showing like primary key not found etc please help me to link EJB application with database application

  • How to call a javascript method after table load on JSFF Fragment load?

    Hello, The usecase is to invoke a javascript method after table is done loading (fetching data) when user lands to a JSFF fragment. With JSPX pages I can achieve that by using PagePhaseListener. I have tried with RegionController as follows, and the

  • Select list from query in report

    Hello everybody, I want to include a select list from a query in a report's colomn, but the select list should only be displayed conditionally. I wanted to do this with the help of "case when" in the corresponding SQL statement. The select list itsse

  • Order costing

    Dear PP experts, We want's to generate one report which will give us Order costs under separate header e.g. Material cost, bought out item cost,Labour cost,set up cost etc... I know we can see the same in each Production Order costing tab. But we wan

  • Open or Save option to download images in JSP

    Hi, I am working on a image bank application that uploads, searches for images saved in a File Server. When the user searches for the images I retrieve the images and I need to give them an option to download the image on click (the same like the bro