How to re-order columns

To change the order of columns in a Grid component you can add the "reroder" attribute:

<t:grid t:source="list" reorder="id,firstname,lastname"/>

How to hide a column

If you want to hide a column from the Grid:

  • Tapestry 5.1:
<t:grid t:source="list" exclude="id"/>
  • Tapestry:
<t:grid t:source="list" remove="id"/>

How link an entry to another page

The person's lastname shall be linked to a page "person/$ID"

<t:grid t:source="list" row="person">
  <t:parameter name="lastnameCell">
    <t:pagelink t:page="person" t:context="person.id">${person.lastname}</t:pagelink>
  </t:parameter>
</t:grid>

How to add an extra column

You want to add an extra column called "details" to each line that does not have a field in the POJO:

<t:grid t:source="list" add="details" row="person">
  <t:parameter name="detailsCell">  <!-- just invent a cell name -->
    <t:pagelink t:page="person" t:context="[person.id,person.lastname]">${person.lastname}</t:pagelink>
  </t:parameter>
</t:grid>

Unfortunately a change in the page class may also be required (if you don't use the "add" parameter above, or have a special model).

public class Page {
  @Inject
  private BeanModelSource beanModelSource;
  @Inject
  private ComponentResources resources;
  private BeanModel model;

  void pageLoaded() {
    this.model = beanModelSource.create(Person.class, true, resources);
    this.model.add("details", null);
  }
  ...

How to add a sortable column

With the above code the column will not be sortable. To make it sortable use

  this.model.add("details",null).sortable(true);

How to disable sorting for a column

It is very likely possible to disable sorting for a column. How is that done? One solution is to create a specific BeanModel for your Grid :

  • Template part :
<t:grid t:source="list" model="model"/>
  • Java part :
    /** The model. */
    @Retain
    private BeanModel model;

    /** The bean model source. */
    @Inject
    private BeanModelSource beanModelSource;

    /** The resources. */
    @Inject
    private ComponentResources resources;

    /**
     * Page loaded.
     */
    void pageLoaded() {
      BeanModel model = beanModelSource.create(Entity.class, false, resources);
      model.get("XXX").sortable(false);
    }

How to define the initial sort column

  • Template part :
<t:grid t:source="list" t:id="theGrid"/>
  • Java part :
    /** The form. */
    @Component
    private Grid theGrid;

    @SetupRender
    public void setupGrid() {
        theGrid.getSortModel().updateSort("XXX");
    }

How to rename a column

You want to rename column called "name" to "account":

  • Template part :
<t:grid t:source="bill" model="model" />
  • Java part :
public class Page {
    /** The model. */
    @Retain
    private BeanModel model;

    /** The bean model source. */
    @Inject
    private BeanModelSource beanModelSource;

    /** The resources. */
    @Inject
    private ComponentResources resources;

  void pageLoaded() {
    this.model = beanModelSource.createDisplayModel(DeviceEquipment.class, resources.getMessages());
    this.model.include("name");
    this.model.get("name").label("account"); // Rename column
  }
  ...

Grid component reference

See http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Grid.html

  • No labels