Secondary Sorting

How do I do a secondary sort?  For example, if I want to sort my songs by Artist and THEN have them alphabetically sorted by song title by each artist?  This used to happen "automatically" in my previous versions of ITunes, but I can not make it work since the upgrade.

iTunes doesn't support user defined secondary sorting. There are a couple of fixed options such as Album by Artist/Year, but that is it.
tt2

Similar Messages

  • Bridge Sort Order - Secondary Sort Key

    Noticed an anamoly to sort order when rating images.
    I have sort order set to Ascending by date. Everything starts off fine - all images in the correct order. When I start labeling the images (using numbers 6, 7, 8, 9) the sort order starts changing.
    I have several images with the same exact date/time (e.g., 8/22/08 10:15:13) - my camera shoots 6 frames per second.
    I start labeling "three" images with the same date/time - as I do, the image I label goes to the "end" of the "three" that have the same date/time stamp. So, now an image I just labeled is moved in the order and I end up labeling it again - which based on how bridge works actually undoes the label - label does a toggle.
    Then I hit the next image and rate it - same thing. appears to be sorting on a secondary key when the date/time are the same for multiple images.
    Is there a way to stop the secondary sort key affect. It really screws up the labeling flow.
    Image order:
    Image01
    Image02
    Image03
    Label Image01 as a "6" - order changes to:
    Image02
    Image03
    Image01
    So now image01 is back in the labeling flow...

    To further explain this issue:
    Original file order:
    1
    2
    3
    I look at each file then star File # 1. Instantly, the files rearrange to:
    3
    2
    1
    So I back track and start the sequence over (so that I can see files 2 and 3). So I decide I also like file # 2. The order rearranges again into:
    1
    3
    2 or something like that
    By now, I'm all mixed up as to what order the event actually happened. The more I star, the more the files rearrange. When I go back to see the rearranged files, they rearrange again. It's all very frustrating when I'm trying to edit a wedding and tell the story. It's imperative that I see all different camera files in order.

  • I highlight genre in my iTunes library and it is sorted thus.  The secondary sort is automatically artist.  I want the secondary sort to be album. How do I accomplish this?

    I highlight "genre" in my itunes library and it is sorted thus.  The secondary sort is automatically "artist".  I want the secondary sort to be "album".  How do I accomplish this?

    Can't do it.
    You can use the browser (iTunes menu view > Browser) select a genre then sort by Album.

  • Secondary sort in itunes

    How do I use a secondary sort in itunes so not only does my list show the artist in alphabetical order, the albums show in chronological as well?
    and can I use Album Artist to sort by last name so I don't have to retype the artist's name so that their last name is listed first in the main itunes window?
    thanks!

    Chris CA wrote:
    Or you can simply sort on Album by Year. Click the Album column header to switch between Album > Album by Artist > Album by Year then back to Album
    This will sort albums by artist by year.
    Yes, but while that is indeed true it's of very limited use as it ONLY applies to the list of tracks currently in the main window. Whereas, if you set up your 'Sort Album' tag/field as I suggest, the list of albums in the 'browse' list at the top (or side) for the selected artist will also be sorted chronologically and there is NO other way to achieve that.
    This chronological sort will also carry over onto the iPods and TVs so almost everywhere you use your music, an Artist's Albums will be sorted chronologically, which as I already opined, is the ONLY way they should be sorted. Just remember to NOT add the date in that way to compilations. This ensures they are grouped together at the top of the Album list for that Artist rather than simply muddling up the list. Mind you, if you do also want them chronologically sorted, you can have that too
    I understand that it is a lot of work to convert a large library of music. With over 1000 CDs it has taken me a long time to achieve an acceptable display for them all, but now, it's a simple matter of adjusting the tags on any new CD I import and that takes only seconds for each one, so it's no longer a big deal. Of course, others may not wish to put in that much effort, but at least I can show that there is a way to achieve it, if you really want.

  • How do I change the secondary sorting on iTunes?

    So iTunes has it's basic sorting algorithm, with various options to choose from for the primary sort.
    However there are secondary, tertiary etc sorts which happen on the rest of the information - so for example, if I sort by Artist, my secondary sort will be albums, and then tertiary will be track number.
    What I want to know is, can I change the default secondary sort? So that if I sort by artist, the secondary sort will be song title or something.
    I know that this capability is present, as Album has various options for sorting if you click it multiple times, specifically Album by Artist and Album by Artist/Year.
    If not present, this feature should be added, because added customisation would be fantastic!

    What I want to know is, can I change the default secondary sort?
    Nope.

  • Adf - secondary sort

    Hi,
    We have adf display only table with 3 columns with the default sort on each column.
    It works fine independantly.
    Is there a way to do a secondary sort on a second column maintaining the first column sort?
    Is there a setting in the column properties that I can use to set this?
    Thanks

    ADF provides only single column sorting, but you can retain the previous sort orders and apply the current sort order as follows:
    1) Create a class variable that retains all the previous sort orders in the managed bean registered in pageFlowScope.
    private List<SortCriterion> tableSortList = new ArrayList<SortCriterion>();
    2) When a sort is performed, if the attribute is already present, remove the old sort criterian for the attribute and add the new one by having custom sort function.
    Here is the sample code:
    Sample.jspx:
    <af:document id="d1">
    <af:messages id="m1"/>
    <af:form id="f1">
    <af:table value="#{bindings.Departments.collectionModel}" var="row"
    rows="#{bindings.Departments.rangeSize}"
    emptyText="#{bindings.Departments.viewable ? 'No data to display.' : 'Access Denied.'}"
    fetchSize="#{bindings.Departments.rangeSize}"
    rowBandingInterval="0"
    selectedRowKeys="#{bindings.Departments.collectionModel.selectedRow}"
    selectionListener="#{bindings.Departments.collectionModel.makeCurrent}"
    rowSelection="single" id="t1"
    *sortListener="#{pageFlowScope.SampleBean.onSort}">*
    <af:column sortProperty="Deptid" sortable="true"
    headerText="#{bindings.Departments.hints.Deptid.label}"
    id="c1">
    <af:outputText value="#{row.Deptid}" id="ot2">
    <af:convertNumber groupingUsed="false"
    pattern="#{bindings.Departments.hints.Deptid.format}"/>
    </af:outputText>
    </af:column>
    <af:column sortProperty="Deptname" sortable="true"
    headerText="#{bindings.Departments.hints.Deptname.label}"
    id="c2">
    <af:outputText value="#{row.Deptname}" id="ot1"/>
    </af:column>
    </af:table>
    </af:form>
    </af:document>
    *SampleBean.java:*
    import java.util.ArrayList;
    import java.util.List;
    import oracle.adf.view.rich.component.rich.data.RichTable;
    import org.apache.myfaces.trinidad.event.SortEvent;
    import org.apache.myfaces.trinidad.model.SortCriterion;
    public class SampleBean {
    public SampleBean() {
    *private List<SortCriterion> tableSortList = new ArrayList<SortCriterion>();*
    *public void onSort(SortEvent sortEvent) {*
    *List currentSortList = sortEvent.getSortCriteria();*
    *SortCriterion currentSortCriterion =*
    *(SortCriterion)currentSortList.get(0);*
    *// Remove the criteria if already present*
    *this.removeIfCurrentSortCriteriaAlreadyPresent(currentSortCriterion);*
    *// Add the current criteria to the list*
    *this.tableSortList.add(currentSortCriterion);*
    *// Print current sorting order for debugging purpose*
    *this.printCurrentSortingOrder();*
    *// Apply the current list of sort criterions to the table*
    *RichTable richTable = (RichTable)sortEvent.getComponent();*
    *richTable.setSortCriteria(tableSortList);*
    private boolean removeIfCurrentSortCriteriaAlreadyPresent(SortCriterion currentSortCriterion) {
    if (tableSortList != null && tableSortList.size() > 0) {
    for (SortCriterion sortCriterion : tableSortList) {
    if (sortCriterion.getProperty().equals(currentSortCriterion.getProperty())) {
    tableSortList.remove(sortCriterion);
    return true;
    return false;
    private void printCurrentSortingOrder() {
    System.out.println(":: CURRENT SORT APPLIED ::");
    if (tableSortList != null && tableSortList.size() > 0) {
    for (SortCriterion sortCriterion : tableSortList) {
    System.out.println(sortCriterion.getProperty() + "----" +
    sortCriterion.isAscending());
    Register the bean in pageFlowScope.
    The code is self explanatory.
    Thanks,
    Navaneeth

  • Secondary sort.

    Hi,
    How do I implement secondary sort order in reports. For example, I have an employee report. I have first_name, last_name, emp_type, login_name etc. I want to give users a way so that when they click on the top of the columns, it should act like this: User first clicks on type then last_name and first_name. Then I want to sort by emp_type, last_name, first_name. Is it possible to do this ? I am using APEX 3.0.
    Thanks

    I could be wrong but I don't think you can do this, The only way I can think of is offering the user a sort selection prior to running the report then using the selected variable to feed a PL/SQL query.
    You could look at a checkbox selection perhaps?

  • Secondary sort order

    I can sort my playlist. But when I sort them in, say "My rating" order, how can I prevent all songs from one artists rated equally being bunched together. What actually decides the sort order within, say, 5 star songs in this case?
    PC   Windows XP Pro  

    No, "limit to N selected by <attribute> will not work, at least I can not figure out to use it to do it. I tried to use "random" as the attribute, but I casn not make it work in a useful way.
    PC AMD Sempron 1,7 GHz 512 MB 140 GB 17" CRT Windows XP Pro iPod Color 30 Gb, 6500 pirated + 20 bought songs

  • Secondary Sorting - Why Not?

    I've searched through the communities and it seems people have asked whether it is possible to create a Smart Playlist in which the songs are sorted by one column, and then where several songs have the same value in a column (say they are all rated five star), to choose a second column to sort by.  The answer, apparently is no.
    Strikes me as being very disappointing.  Your iTunes library is, after all, simply a database, and if you can easily sort and filter by several columns in a spreadsheet or database, then it should be easy to do so in iTunes.
    The default, it seems is for iTunes to always sort by Artist after it has sorted by your choice of sort column, which means that if you've got a smart playlist for all your favourite ska tracks, sorted in order of rating from five star to three, then you're going to have to listen to them either in a completely random order, or you're going to have to always listen to a string of Bad Manners, then The Beat, The Bodysnatchers, Madness, BB Seaton, Selecter, The Specials, etc.  It'd be really nice to shuffle that up a bit, but still have your top rated stuff first.
    Would there be support from the community for what must be a simple piece of database programming?

    Suggestions here -> http://www.apple.com/feedback/

  • ALV (Secondary) SORTING????

    Hi Experts,
    Am getting sorting as per my requirement [i.e.
    1.Material # (ascending)...2.Last Price Change Date (most recent first)..3. Plant (ascending)] in my_ITAB, with the following code,
       <i><b>sort i_out ascending
                by   matnr ascending
                      laepr descending
                      werks ascending  .</b></i>
    But, wanna to get it the same in ALV, so I hv written the code as follows, but NOT working??? particularly, the Last change date of the price, is not sorting(its displaying defaultly/just ascending)
    So, how to get it done? Is it some wht related with WA_SORT-GROUP field populating?
    <i><b>*  wa_sort-spos      = 1.
    wa_sort-fieldname = 'MATNR'.
    wa_sort-tabname   = 'I_OUT'.
    wa_sort-up        = 'X'.
    APPEND wa_sort TO alv_sort.
    wa_sort-spos      = 2.
    wa_sort-fieldname = 'LAEPR'.
    wa_sort-tabname   = 'I_OUT'.
    wa_sort-up        = 'X'.
    wa_sort-down      = 'X'.
    APPEND wa_sort TO alv_sort.
    wa_sort-spos      =  3.
    wa_sort-fieldname = 'WERKS'.
    wa_sort-tabname   = 'I_OUT'.
    wa_sort-up        = 'X'.
    APPEND wa_sort TO alv_sort.</b></i>
    thanq.

    Well, for one, the sort logic is commented out.     Once you have uncommented it, I would think that this would work, and that you are passing the ALV_SORT to the actually FM call.
    * UP
    wa_sort-spos = 1.
    wa_sort-fieldname = 'MATNR'.
    wa_sort-tabname = 'I_OUT'.
    wa_sort-up = 'X'.
    APPEND wa_sort TO alv_sort.
    * DOWN
    wa_sort-spos = 2.
    wa_sort-fieldname = 'LAEPR'.
    wa_sort-tabname = 'I_OUT'.
    * wa_sort-up = 'X'.
    wa_sort-down = 'X'.
    APPEND wa_sort TO alv_sort.
    * UP
    wa_sort-spos = 3.
    wa_sort-fieldname = 'WERKS'.
    wa_sort-tabname = 'I_OUT'.
    wa_sort-up = 'X'.
    APPEND wa_sort TO alv_sort.
    Regards,
    RIch Heilman

  • How can I sort albums by album artist while keeping compilations together?

    Argh, I'm getting a bit exasperated. Basically I just want to be able to scroll through cover flow and see all my albums with one cover representing each album, with all the compilations near the end under "V" for various. Surely most people would want to scroll through their albums in this way??
    So I've gone through and added all the album artist info, which has worked fine for the artist albums. But for all the "Various" ones, instead of doing the logical thing and grouping them together by album, iTunes orders these all by track artist. There doesn't seem to be any secondary sort function..
    I'm always defending Mac and Apple products for their logical applications and ease of use, and now I feel let down.. If there's a way around this please let me know! Thanks,
    Malinna

    The trouble you're encountering is that iTunes sorts first by Album Artist, then by Artist. Thus, within each Album Artist, you'll get multiple Artist clumps.
    You want to sort "Album by Artist". This will, first, strip out all your compilations and sort them to the end of your library, then sort using the hierarchy Album Artist (or Artist if there is none) > Album > Disc # > Track #. Click the Album column header until Album by Artist is displayed. (You can also choose Album by Year, which will sort albums chronologically within Album Artist.)
    If you want to keep albums together, you'll need to sort on an Album column; other columns are bound to clump things by whatever you're sorting on.

  • JTable sorting - problem when adding elements (complete code inside)

    I�m writing this email with reference to a recent posting here but this time with the code example. (I apologize for the duplicated posting � this time it will be with the code)
    Problem: when adding more elements to the JTable (sorted) the exception: ArrayIndexOutOfBoundsException is thrown.
    Example: If the elements in the table are 10 and then the user requests for 8 � the table will produce the correct result. However, if the user will ask for 11 items (>10) the exception will be thrown.
    The program: The program below (compiles and running). A JTable is constructed with 3 items, when you click the button - the return result should be 4 items - this will generate the error, WHY?
    I would highly appreciate your thoughts why this is happening and most importantly � how to fix it.
    Thanks a lot
    3 files:
    (1) TableSorterDemo
    (2) Traveler
    (3)TableSorter
    //TableSorterDemo:
    package sorter;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    * TableSorterDemo is like TableDemo, except that it
    * inserts a custom model -- a sorter -- between the table
    * and its data model.  It also has column tool tips.
    public class TableSorterDemo implements ActionListener
         private JPanel superPanel;
         private JButton clickMe = new JButton("click me to get diff data");
         private boolean DEBUG = false;
         private DefaultListModel defaultListModel;
         private JTable table;
        public TableSorterDemo()
             superPanel = new JPanel(new BorderLayout());
             defaultListModel = new DefaultListModel();
             init1();
            TableSorter sorter = new TableSorter(new MyTableModel(defaultListModel)); //ADDED THIS     
            table = new JTable(sorter);             //NEW
            sorter.setTableHeader(table.getTableHeader()); //ADDED THIS
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            //Set up tool tips for column headers.
            table.getTableHeader().setToolTipText(
                    "Click to specify sorting; Control-Click to specify secondary sorting");
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            superPanel.add("Center", scrollPane);
            superPanel.add("South",clickMe);
            clickMe.addActionListener(this);              
        public JPanel getPanel()
             return superPanel;
        public void init1()
             //in real life this will be done from the db
             Traveler a = new Traveler();
             Traveler b = new Traveler();
             Traveler c = new Traveler();
             a.setFirstName("Elvis");
             a.setLastName("Presley");
             a.setSprot("Ping Pong");
             a.setNumYears(3);
             a.setVegetarian(true);
             b.setFirstName("Elton");
             b.setLastName("John");
             b.setSprot("Soccer");
             b.setNumYears(2);
             b.setVegetarian(true);
             c.setFirstName("shaquille");
             c.setLastName("oneil");
             c.setSprot("Golf");
             c.setNumYears(22);
             c.setVegetarian(true);
             defaultListModel.addElement(a);
             defaultListModel.addElement(b);
             defaultListModel.addElement(c);
        public void init2()
             //in real life this will be done from the db
             Traveler d = new Traveler();
             Traveler e = new Traveler();
             Traveler f = new Traveler();
             Traveler g = new Traveler();
             d.setFirstName("John");
             d.setLastName("Smith");
             d.setSprot("Tennis");
             d.setNumYears(32);
             d.setVegetarian(true);
             e.setFirstName("Ron");
             e.setLastName("Cohen");
             e.setSprot("Baseball");
             e.setNumYears(12);
             e.setVegetarian(true);
             f.setFirstName("Donald");
             f.setLastName("Mac Novice");
             f.setSprot("Vallyball");
             f.setNumYears(1);
             f.setVegetarian(true);
             g.setFirstName("Eithan");
             g.setLastName("Superstar");
             g.setSprot("Vallyball");
             g.setNumYears(21);
             g.setVegetarian(true);
             defaultListModel.addElement(d);
             defaultListModel.addElement(e);
             defaultListModel.addElement(f);
             defaultListModel.addElement(g);            
        class MyTableModel extends AbstractTableModel
             private DefaultListModel myModel;
             public MyTableModel(DefaultListModel m)
                  myModel=m;
            private String[] columnNames = {"First Name",
                                            "Last Name",
                                            "Sport",
                                            "# of Years",
                                            "Vegetarian"};
            public int getColumnCount()
                return columnNames.length;
            public int getRowCount()
                return myModel.size();
            public String getColumnName(int column)
                 return getNames()[column];             
             public String[] getNames()
                  String[] names = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
                  return names;
            public Object getValueAt(int row, int col)
                 return distributeObjectsInTable(row, col, (Traveler) myModel.elementAt(row));
            public Object distributeObjectsInTable(int row, int col, Traveler tr)
               switch(col)
                         case 0:
                              return tr.getFirstName();
                         case 1:
                           return tr.getLastName();
                      case 2:
                           return tr.getSprot();
                      case 3:
                           return new Integer(tr.getNumYears());
                      case 4:
                           return new Boolean (tr.isVegetarian());
                     default:
                         return "Error";
            public Class getColumnClass(int c)
                return getValueAt(0, c).getClass();
        private static void createAndShowGUI()
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("TableSorterDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            TableSorterDemo newContentPane = new TableSorterDemo();
            newContentPane.getPanel().setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane.getPanel());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args)
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable()                   
                public void run()
                    createAndShowGUI();
         public void actionPerformed(ActionEvent ae)
              if (ae.getSource()==clickMe)
                   defaultListModel.removeAllElements();
                   init2(); //if the size of the model was less than 2 items - the result will be ok.
                              //in other words, if you commens the last 2 rows of this method (addElement(f) & g)
                             // the result will be fine.
                   table.updateUI();          
    }//(2) Traveler
    package sorter;
    public class Traveler
         private String firstName;
         private String lastName;
         private String sprot;
         private int numYears;
         private boolean vegetarian;
         public String getFirstName()
              return firstName;
         public String getLastName()
              return lastName;
         public int getNumYears()
              return numYears;
         public String getSprot()
              return sprot;
         public boolean isVegetarian()
              return vegetarian;
         public void setFirstName(String firstName)
              this.firstName = firstName;
         public void setLastName(String lastName)
              this.lastName = lastName;
         public void setNumYears(int numYears)
              this.numYears = numYears;
         public void setSprot(String sprot)
              this.sprot = sprot;
         public void setVegetarian(boolean vegetarian)
              this.vegetarian = vegetarian;
    }//(3)TableSorter
    package sorter;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    public 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 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 the table structure has changed, cancel the sorting; the            
                // sorting columns may have been either moved or deleted from            
                // the model.
                if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                    cancelSorting();
                    fireTableChanged(e);
                    return;
                // We can map a cell event through to the view without widening            
                // when the following conditions apply:
                // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
                // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
                // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
                // d) a reverse lookup will not trigger a sort (modelToView != null)
                // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
                // The last check, for (modelToView != null) is to see if modelToView
                // is already allocated. If we don't do this check; sorting can become
                // a performance bottleneck for applications where cells 
                // change rapidly in different parts of the table. If cells
                // change alternately in the sorting column and then outside of            
                // it this class can end up re-sorting on alternate cell updates -
                // which can be a performance problem for large tables. The last
                // clause avoids this problem.
                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;
    }

    The table listens to the TableModel for changes. Changing the table by adding/removing
    rows or columns has no affect on its table model. If you make changes to the table model
    the table will be notified by its TableModelListener and change its view. So tell
    MyTableModel about the change of data:
    public class TableSorterDemo implements ActionListener
        MyTableModel tableModel;
        public TableSorterDemo()
            defaultListModel = new DefaultListModel();
            init1();
            tableModel = new MyTableModel(defaultListModel);
            TableSorter sorter = new TableSorter(tableModel);
        public void actionPerformed(ActionEvent ae)
            if (ae.getSource()==clickMe)
                defaultListModel.removeAllElements();
                init2();
                tableModel.fireTableStructureChanged();
    }

  • Sort order of album ignoring track #

    I am having a problem where track 9 of a specific 14 track album is listed between tracks 11 and 12 rather than between 8 and 10. I have removed and re-imported the folder at least 10 times. I have tried all of these things before re-importing:
    Renamed the files
    Re-encoded the files
    Updated the ID3 tags of the files
    Still I cannot change how iTunes chooses to sort this album. It's almost as if the secondary sort criteria were not track # but some other attribute that eludes me. This is driving me insane. I can't figure out a way to get this album to simply play in order, other than to create an independent playlist just for that one album.... and that doesn't really mesh with the way I use it.
    Can someone help me?
    My 20th or so   Windows XP Pro  

    Try making sure they all have the same "album artist" field filled in. if any of them are blank, these get put at the top. or the end... i forget. also, make sure they all say, "disc 1 of 1" in the track info. that should put them in track order.
    Toshiba Laptop   Windows XP  

  • Sort by Artist / Date in List View

    I like to have my albums sorted by Artist and then chronologically by Release Date
    This is fine in Grid View as i can sort by Artist and within that by Date.
    But when i switch to List View it sorts by Artist and within that by Album Title.
    There doesn't appear to be an option to specify a secondary sort field in List View.
    I could live with this in iTunes since I browse in Grid Mode
    but I presume it will download to my ipod in List View.
    So am i missing a trick here - is there a way around this?

    delia0027 wrote:
    I lose sleep over this oversight by Apple.
    Would you like some suggestions of where you can get help for that? Economy is in the toilet, people are out of work, losing thier homes, can't retire after working for decades, etc. but that a couple albums released in the same calendar year don't sort in order of release in iTunes...
    delia0027 wrote:
    How can this be? They are so particular about everything and they don't see this as a problem for serious music people?
    I can remember before there was such a thing as iTunes and people actually listened to their music and enjoyed it. It didn't matter when they last heard the song, how many times they have heard it, didn't have to write down which were their favorites and which were not, we just knew which ones we liked, etc.. Not anymore. Now people are concerned more with how many times a song has been played, ranking their library in order of their favorites, being sure to know when they last played some song, the order of two albums released in 1968 (even though the "serious music people" should just know that), etc.
    It makes me wonder if people actually listen to their music anymore since they seem much too busy cataloging, sorting, rating, and making sure their playcounts get updatred correctly. I honestly think iTunes may have messed up the way people listen to and enjoy music now. It is kind of sad really.
    Patrick

  • Group by sort order and display accordingly

    I have two groups - primary sort order and a secondary sort order in my report, formula for both follows:
    If {?Sort Order}='1' then {PRODUCT_CUSTOMER_MNT_V.CUSTOMER_NAME}
    else if {?Sort Order}='2' then {PRODUCT_CUSTOMER_MNT_V.PRODUCT_ID}
    else if {?Sort Order}='3' then {PRODUCT_CUSTOMER_MNT_V.CUST_REVISION_LEVEL}
    else if {?Sort Order}='4' then {PRODUCT_CUSTOMER_MNT_V.CMS_UD36}
    else if {?Sort Order}='5' then {PRODUCT_CUSTOMER_MNT_V.CMS_UD38}
    else if {?Sort Order}='6' then totext(year({PRODUCT_CUSTOMER_MNT_V.PURCHASE_DATE}),0,"")"/"
    right("0" + totext(month({PRODUCT_CUSTOMER_MNT_V.PURCHASE_DATE}),0,""),2)"/"
    right("0" + totext(day({PRODUCT_CUSTOMER_MNT_V.PURCHASE_DATE}),0,""),2)
    Groups are suppressed and fields are placed in the detail the line.  I have a request to group by Customer name with selected product ID's listed or vice versa.   My quandry is how do I accomodate the descriptive fields in the page header since the user can select any number of combinations using the sort order parameter.  Sure, right now they are only looking at customer and product ID but let's face it, that requirement could change in the future.  Seems simple enough but it's been awhile since I've touched reports and my brain is fuzzy.  Is what I'm trying to do possible?   Crystal XI (11.0.0.1282)

    I was overthinking the problem.  The report was already sorting on customer or product based on user selection.  I placed the customer ID/Name field and the Product ID field into group one and checked the underlay following section box in section expert.  This is will work fine for our purposes.

Maybe you are looking for