Sort Table

Hi,
Is possible reorder a table items or table container items by some property IDs like

Order by property1,property2,property3

Any idea?

Thank you!!

Xavier

Is
Table.sort(Object[] propertyId, boolean[]
ascending)
what you are looking for?

Thanks!!
Yes but how, i’m trying and something is wrong on my code because do no work,




		IndexedContainer id= new IndexedContainer();
		id.addContainerProperty("date", java.util.Date.class, null);
		id.addContainerProperty("city", String.class, null);
		id.addContainerProperty("amount", Float.class, null);
               table.setContainerDataSource(id);
                Object [] properties={"date","amount"};
                table.sort(ordering,true);    //ERROR HERE

Thank you!

I think this will help.


Object [] properties={"date","amount"};
boolean [] ordering={true,false};
sort(properties, ordering);

Thank you again

Works!!!

I can not seem to get a table to sort for some reason. Below is the code where I attach the table to the container data source, which is a bean container, and build the table. When I run the sort command the table does not sort by the property identified and when I try to get the sort container property id, it is null. I can click on a column and then everything is sorted. I have also tried using the setSortContainerPropertyId and setSortAscending and it still does not sort, but at least the SortContainerPropertyId is set correctly. What am I missing?

    this.tbl_Deliveries.setContainerDataSource(this.m_ShortDelivRecs.getRecords());
    
    this.tbl_Deliveries.setVisibleColumns(new Object {"delivDate", "ticketNo", "volume", "notFull", "runout", "projDDay", "delivDDay","intervalDDay", "calendarDays", "kfactAdj", "computedK"});
    
    this.tbl_Deliveries.setConverter("delivDate", new DateConverter(DateConverter.DateFormat.MDY_LONG));
    this.tbl_Deliveries.setColumnWidth("delivDate", this.dateWidth);
    this.tbl_Deliveries.setColumnHeader("delivDate", "date");
    this.tbl_Deliveries.setColumnAlignment("delivDate", Align.CENTER);
    
    this.tbl_Deliveries.setConverter("ticketNo", new IntegerConverter("####0"));
    this.tbl_Deliveries.setColumnWidth("ticketNo",this.ticketWidth);
    this.tbl_Deliveries.setColumnHeader("ticketNo","ticket#");
    this.tbl_Deliveries.setColumnAlignment("ticketNo", Align.CENTER);
    
    this.tbl_Deliveries.setConverter("volume", new DecimalConverter("###0.0"));
    this.tbl_Deliveries.setColumnWidth("volume", this.volumeWidth);
    this.tbl_Deliveries.setColumnHeader("volume","volume");
    this.tbl_Deliveries.setColumnAlignment("volume",Align.RIGHT);
    
    this.tbl_Deliveries.setConverter("notFull", new BooleanConverter("NF",""));
    this.tbl_Deliveries.setColumnWidth("notFull", this.notFullWidth);
    this.tbl_Deliveries.setColumnHeader("notFull","");
    this.tbl_Deliveries.setColumnAlignment("notfull",Align.CENTER);
    
    this.tbl_Deliveries.setConverter("runout", new BooleanConverter("RO",""));
    this.tbl_Deliveries.setColumnWidth("runout", this.runoutWidth);
    this.tbl_Deliveries.setColumnHeader("runout", "");
    this.tbl_Deliveries.setColumnAlignment("runout", Align.CENTER);
    
    this.tbl_Deliveries.setConverter("projDDay",new IntegerConverter("###0"));
    this.tbl_Deliveries.setColumnWidth("projDDay",this.ddayWidth);
    this.tbl_Deliveries.setColumnHeader("projDDay", "proj");
    this.tbl_Deliveries.setColumnAlignment("projDDay", Align.RIGHT);
    
    this.tbl_Deliveries.setConverter("delivDDay", new IntegerConverter("###0"));
    this.tbl_Deliveries.setColumnWidth("delivDDay",this.ddayWidth);
    this.tbl_Deliveries.setColumnHeader("delivDDay", "deliv");
    this.tbl_Deliveries.setColumnAlignment("delivDDay", Align.RIGHT);

    this.tbl_Deliveries.setConverter("intervalDDay", new IntegerConverter("###0"));
    this.tbl_Deliveries.setColumnWidth("intervalDDay",this.ddayWidth);
    this.tbl_Deliveries.setColumnHeader("intervalDDay", "intervl");
    this.tbl_Deliveries.setColumnAlignment("intervalDDay", Align.RIGHT);

    this.tbl_Deliveries.setConverter("calendarDays", new IntegerConverter("###0"));
    this.tbl_Deliveries.setColumnWidth("calendarDays",this.ddayWidth);
    this.tbl_Deliveries.setColumnHeader("calendarDays","days");
    this.tbl_Deliveries.setColumnAlignment("calendarDays", Align.RIGHT);

    this.tbl_Deliveries.setConverter("kfactAdj", new DecimalConverter("###0.00"));
    this.tbl_Deliveries.setColumnWidth("kfactAdj",this.kfactWidth);
    this.tbl_Deliveries.setColumnHeader("kfactAdj","Adjust");
    this.tbl_Deliveries.setColumnAlignment("kfactAdj", Align.RIGHT);

    this.tbl_Deliveries.setConverter("computedK", new DecimalConverter("###0.00"));
    this.tbl_Deliveries.setColumnWidth("computedK",this.kfactWidth);
    this.tbl_Deliveries.setColumnHeader("computedK","compute");
    this.tbl_Deliveries.setColumnAlignment("computedK", Align.RIGHT);
    
    Object sortColumn = "ticketNo";
    boolean sortOrder = false;

    this.tbl_Deliveries.sort(new Object {sortColumn}, new boolean {sortOrder});
    
    System.out.println(this.tbl_Deliveries.getSortContainerPropertyId() + " " + this.tbl_Deliveries.isSortAscending() + " " + this.tbl_Deliveries.isSortEnabled());

Hi,

I was trying out sorting behavior of tables when I saw this post. I have been able to get this working so just posting a reply just in case you are still facing the issue.
You can specify sort property ID using
table.setSortContainerPropertyId()
Then you can choose the order by using
table.setSortAscending() // by default it is ascending

The table will still not be sorted yet. Only the parameters and properties have been specified.
You will have to call
table.sort()
explicitly to sort the table and make sure you call this just before returning your table to client otherwise you might see some odd behavior.

So I just needed that one line to fix something after spending a day digging through source code? Could you dumb it down a little for me? :slight_smile:

Thanks for this tip,
Bobby

I have not spend too much time in going into the details as to why such behavior is there. So I guess you would be having more technical details than me :slight_smile: I just posted my experience of the issue and how it worked for me.

I’m using a grid and I have colum with string data in it. The strings are in serbian cyrilic. The default sorting of this column doesn’t sort strings correctly. Could you please tell me is there a common way to change the default sorting?