Quantcast
Channel: XPages – Xcellerant
Viewing all articles
Browse latest Browse all 216

Dojo Data Grid – Part 14: Enhanced Filtering with No Coding!

$
0
0

Dojo EnhancedGrid plugins take the functionality of the grid to a whole new level. In this post, we’ll look at the tremendous Filter plugin, which allows users to create multiple filtering rules with many matching options — all with no coding whatsoever!

Dojo Data Grid Series

Start with a Dojo EnhancedGrid

Before you can use an EnhancedGrid plugin, you need to be set up the Dojo Data Grid control to render as a Dojo EnhancedGrid. Follow the steps in this post to get ready.

1. Load the Filter Plugin

The dojox.grid.enhanced.plugins.Filter module must be included on the page, so add it to the page resources. Properties > Resources > Add > Dojo Module…
Dojo_14_1_AddFilterModules

2. Add the Plugin to the Grid

The first step made the plugin module available, but you also need to add it to the grid.

Go to the properties of the Dojo Data Grid > Dojo and click the Add button. Add the property as shown here:
Dojo_14_2_AddPluginProperty

3. Add a style sheet

In addition to the style sheets listed in the previous post, you need an additional style sheet for the filter bar and filtering dialog to format properly.

Add this style sheet to the page resources as well:

/.ibmxspres/dojoroot/dojox/grid/enhanced/resources/claro/EnhancedGrid.css

All together, the resources of the page should look like this:

<xp:this.resources>
  <xp:dojoModule name="dojox.grid.EnhancedGrid"></xp:dojoModule>
  <xp:dojoModule name="dojox.grid.enhanced.plugins.Filter"></xp:dojoModule>
	
  <xp:styleSheet
    href="/.ibmxspres/dojoroot/dojox/grid/resources/Grid.css">
  </xp:styleSheet>
  <xp:styleSheet
    href="/.ibmxspres/dojoroot/dojox/grid/resources/EnhancedGrid.css">
  </xp:styleSheet>
  <xp:styleSheet
    href="/.ibmxspres/dojoroot/dojox/grid/enhanced/resources/claro/EnhancedGrid.css">
  </xp:styleSheet>
</xp:this.resources>

Filtering Enabled

When you load the grid, you will now see the filter bar appearing directly below the column headers.
Dojo_14_3_FilterBar

Filtering the Grid

To filter the data, click on the icon on the left of the filter bar in order to pop up the filtering dialog.
Dojo_14_5_FilterDialog

FWIW – This is what it looks like without that extra style sheet:
Dojo_14_4_FilterPopup_NoStyleSheets

Filter Rules

You can set the filtering to match all or any of the specified rules.

For each rule, you select a column and condition and enter a value.

The Column options are ‘Any Column’ or any specific column in the grid. (You can add properties to grid columns to prevent them from being filterable.)

The Condition option determines how it searches the column. It defaults to ‘contains’, but has many other options for matching the data.
Dojo_14_6_FilterConditions

Multiple Rules

You can add up to 3 filtering rules. The dialog provides a nice accordion interface to modifying the rules.
Dojo_14_7_MultipleRules

Results

When you click the button to execute the filter, the grid is updated with the results. It gives you a count of items and the total that were searched. It also provides a link to clear the filter and display the full data set.
Dojo_14_8_FilterResults

Bonus — It’s Sortable!

You can even sort the filtered results.

I am thoroughly impressed that this works so well with so little effort. Keep an eye on performance, though, because it has to hit the server to filter the data.

REST Service Type – Important

The filtering seems to work well when the grid is bound to a viewItemFileService rest service. It does not work with a viewJsonService service.

More Information

For more information about the Filtering plugin, check out the documentation.



Viewing all articles
Browse latest Browse all 216

Trending Articles