Search code examples
isis

How to order collection columns in Apache isis?


I am using apache ISIS for almost a year and it is a great framework. I am trying to improve the usability of the generated user interface and I am looking for a way to order the columns of a collection as displayed on the screen.

I could not find a way to order the columns using @Collection or @CollectionLayout and could not find an example if it is possible in the layout.xml file.

It would really improve the usability of my user interface if the most relevant columns of a collection would be displayed first - on the left side of the table - in the table view.

(My domain entities showed in a collection property often have a super class defining common fields. The display of attributes of a single entity is perfect using layout.xml and the bootstrap layout, but I still looking for a similar construct for collections displayed as tables in the user interface. I could not find any hints in the documentation or the advanced guide).

Thanks for any hints how I could control the order of columns in a table displaying a collection of domain entities and improve the user interface usability.


Solution

  • nice to know you're enjoying using the framework.

    The way to do this with annotations is using @MemberOrder, not @CollectionLayout.

    However, if you have a layout.xml file then this (should) override the @MemberOrder annotation. In which case, the order of the columns is the same as the order of the properties in the layout.xml.

    You can also use the <collection id="xxx" hidden="ALL_TABLES"> (or alternatively @CollectionLayout(hidden=Where.ALL_TABLES)) to hide properties that you don't want to appear as columns.

    All that said, I did recently discover what I think is a bug (on 1.13.0): that the layout.xml seemed to be being ignored for the collection order, even though used for the object form. This isn't consistent and I haven't got to the bottom of it. My workaround was to just add in the @MemberOrder annotations back in; this did the trick.

    One other caveat: if you have a complex mix of tabs and regular fieldsets, then you'll find that those properties in tabs are considered to be first, even if there's a property in a fieldset that comes before it. This is arguably a bug, but it's a symptom of the implementation: the code does a deep traversal of tabgroups/tabs before the fieldsets.

    Finally, here's a trick. What you could do is to define a bunch of derived properties on the entity for which you want to show in columns, and configure so that only these are shown in tables, and are hidden in object form, eg:

    public class Customer {
        @Getter @Setter private String name;
        public String getNameAsColumn() { return getName(); }
    }
    

    then in the layout.xml:

    <property id="name" hidden="ALL_TABLES"/>
    <property id="nameAsColumn hidden="OBJECT_FORMS">
        <named>Name</named>
    </property>
    

    HTH Dan