How to sort table when it is been rendered

Hi,

I am creating a Table and am using a default container (i.e. Indexed Container) for it. I have two different sets of Objects which have I want to categorize in the table as the table gets populated/rendered. The property of the object is what decides If the object belongs to the first category or the second category and the table does not have that column as visible. So, how can I sort rows belonging to two categories when I have a table, and Indexed container and a property which does not have any visible column related to it but which defines which object belongs to what category. Also, How can I have introduce some style (like a dark black line) so that I can view the two categorise seperately.

final Table table = new Table(caption);
final List<Object> visibleColumns = new ArrayList<Object>();

table.addContainerProperty("id", Integer.class, null);
table.addContainerProperty("User/Group", Label.class, null);
visibleColumns.add("User/Group");
for (final String permission : perms) {
    table.addContainerProperty(permission, NativeSelect.class, null);
    visibleColumns.add(permission);
}

table.setVisibleColumns(visibleColumns.toArray());
table.setSortEnabled(false);

Integer tableId = new Integer(0);

final IndexedContainer container = (IndexedContainer) securityTable.getContainerDataSource();

if (container instanceof IndexedContainer) {
    final Collection<?> propIds = container.getSortableContainerPropertyIds();
    final List<NativeSelect> nativeSelects = createNativeSelects();
    final Object[] labelArray = {
                 userName
                };
   final Object[] nsArray = nativeSelects.toArray(new Object[nativeSelects.size()]
);
   final Object[] row = new Object[nativeSelects.size() + 1]
;

   System.arraycopy(labelArray, 0, row, 0, labelArray.length);

   System.arraycopy(nsArray, 0, row, labelArray.length, nsArray.length);

   final Object id = securityTable.addItem(row, tableId);
   final Item item = container.getItem(id);
   item.getItemProperty("id").setValue((userSid.isPrinciple() == true) ? tableId : tableId * 100);
   tableId++;
}

Hi,

if you repopulate the container the table will update, so if you want to alter the sorting of your elements and the property upon which you want to sort is not visible, then I presume you will fire the sort event via another component. So in that case if you repopulate the table container, it will update and make the same effect. So you can sort via a custom Comparator which refers to your hidden property and redo the container. That’s the most straightforward solution I can think of.

As for the row styling you have a method in the Table object which allows precisely that, going down to cell level, via the property and the item id.

table.setCellStyleGenerator(new Table.CellStyleGenerator() {
        public String getStyle(Object itemId, Object propertyId) {

Hope it helps.

Carlos.