Search code examples
javaeclipse-pluginswtnattable

Sorting and filtering in Nattable with Column Grouping


Background:

I have referred NatTable examples for integrating both sorting and filtering along with column grouping functionalities into a single table. It is not working as expected. If I try to add Sorting and filtering features individually it works like a charm but the integration of both with column grouping is not working. Based on the suggestions here I have tried to add the needed configurations to the nattable but still it doesn't work.

Code Snippet :

  /**
   * Sorting Layer
   */
  GridLayer gridLayer = new GridLayer(viewportLayer,columnGroupHeaderLayer, rowHeaderLayer, cornerLayer);
  /**
   * Since I am able to add only single grid layer to nat table
   */
  this.natTable = new NatTable(parent, gridLayer, false);
   /**
   * FilteringLayer
   */
  this.grid = new FilterableGridLayer(this.eventList, propertyNames, propertyToLabelMap, configRegistry);              
  this.natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
  this.natTable.addConfiguration(new SingleClickSortConfiguration());
  this.natTable.addConfiguration(new FilterRowConfiguration());
  this.natTable.setConfigRegistry(configRegistry);
  this.natTable.configure();

Is there is any way to add both the sort and filter grid layer along with the column grouping into a single nat table?


Solution

  • Have a look at the NatTable Examples Application

    NatTable Examples -> Tutorial Examples -> Integration -> SortableFilterableColumnGroupExample

    This example shows exactly the requested feature combination. Please notice that this example does not include the SingleClickSortConfiguration. This means sorting is only triggered by keeping the ALT key pressed while clicking on the column header. Pressing ALT + SHIFT and click will support up to three levels in sorting.

    If you want to sort on a single click, you need to additionally add the SingleClickSortConfiguration before calling NatTable#configure().

    this.natTable.addConfiguration(new SingleClickSortConfiguration());