Jan 282014

List views are an important component of the OpenText Content Server interface. In a nutshell, a list view provides a summary of related information and is often rendered in an HTML table. Consider a few examples of list views in Content Server:

  • folder browsing;
  • audit tab;
  • assignments list;
  • user lists;
  • group membership list;
  • task list;
  • LiveReport;
  • etc.

The majority of list views benefit when operations are available to help find and organize the contents of the view. Common operations are sorting, filtering, and paging. Let’s review:

  • Sorting. Sorting is usually applied by clicking a column header. This causes a page refresh or AJAX request to fetch the sorted information from the server. In some situations the sort can be applied by the client (with JavaScript) without making a new server request.
  • Filtering. With large list views it can get difficult to find what you’re looking for. A filter allows a user to type in some text or select a rule (e.g., a date range) to reduce the result set.
  • Paging. A single page with thousands of items provides an unfriendly browsing experience. A page with millions of items takes long to render and will likely cause the browser or server to crash. Pagination reduces the number of items on the screen, gives visual indication that more information is available, and allows the user to jump to a page by clicking a page number or “Next” button.

Unfortunately, Content Server doesn’t provide a generic approach to apply these operations. Although Content Server has some of these features in their views, the solutions are proprietary to the view and can’t be reused in other contexts. In other words, the basic logic behind sorting, filtering, and paging is rewritten each time it’s required.

Introducing Paginator

To address this problem I created the Paginator class, which is a component of the RHCore framework. The class wraps a RecArray and provides methods to assist with sorting, filtering, and paging. Let’s jump in with an example:

// for brevity we skip error checking
RecArray recs = CAPI.Exec(prgCtx.fDbConnect.fConnection, "select * from DTree")

// construct a paginator instance
Frame paginator = $RHCore.Paginator.New(recs)

A Paginator object has a number of useful methods:

// returns the total number of Records
Integer totalNumberOfItems = paginator.count()

// set the page size to 25 items per page

// fetch the number of pages, which will depend on the pageSize
Integer pageCount = paginator.pageCount() 

// apply a filter and reduce the set to items where
// the "name" column contains the string "Enterprise"

// pageCount will return a different value than before now that a 
// filter has been applied
pageCount = paginator.pageCount()

// set the page number we'd like to view

// check if we have a next page (i.e., page 4)
// (this method is useful when rendering Previous/Next buttons)
Boolean nextPageExists = paginator.hasNext()

// sort the contents by name, descending order

The sorted and filtered items for the page are retrieved with the items() or iterator() method. The items() method returns the page as a RecArray while the iterator() method returns an Iterator object (see the section on iterators in Part II of this blog series).

RecArray myPagedFilteredSortedItems = paginator.items()

// or

Frame myPagedFilteredSortedIterator = paginator.iterator()

This means we can render the Paginator object in our WebLingo or RHTemplate by iterating the output of one of these methods. The developer still needs to create the user interface components to interact with these features, but this is easy to do with RHTemplate. RHTemplate has a filter, sort, and paginator filter, which can be used to apply filtering, sorting, and paging to a data set directly from within a template.

For rendering the developer can use the provided paginator.html template widget:

{% include "rhcore/paginator.html" with paginator=paginator pageParm="page" %}

This will render a basic pagination component with the page count, item count, and highlighted page in the following style. It also manages the URL generation as defined by the pageParm parameter (e.g., &page=3):

A widget is also available for creating sort headers with the appropriate URL and up/down arrows. More information on the sort header macro can be found in Part III of this blog series.


You may have recognized a problem with the previous example: What if the select * from DTree call returns a million rows? This would certainly cause performance problems and likely crash the server. To get around this I created a subclass of Paginator called RHQuery, which behaves like Paginator but manages everything at the database level. To the developer it has the same interface except for the constructor, which looks like this:

Frame paginator = $RHCore.RHQuery.New(prgCtx, "select * from DTree")

Everything else in the example is exactly the same. The difference is that sorting, filtering, and paging are handled by the database and makes using the control possible over a million items. Behind the scenes this is done by extending the SQL query before making the database call. Provisions are in place to prevent SQL injection and to ensure parameters are valid (e.g., the sort parameter is a valid column). This means a developer can set parameters on the Paginator object directly from a request value. For example:



Similarly, a subclass of RHQuery called LiveReportQuery is available and allows a Paginator object to be constructed from a LiveReport. The object ignores the “Record Limit” field and allows the data from a LiveReport to be punched up with filtering, sorting, and paging without having to embed any of that logic in the LiveReport itself.

Wrapping Up

The Paginator class and its subclasses are all key-value compliant and work seamlessly with RHModel and RHTemplate. I’m using it in a number of projects and with just a few lines of a code can add paging to any list view that requires it. It’s efficient, reusable, and convenient. I couldn’t imagine doing it any other way.

Questions or comments? Leave a comment below.

Need help developing for Content Server or interested in using RHCore? Contact me at cmeyer@rhouse.ch.

  4 Responses to “Part V – Paging, Sorting, & Filtering in OpenText Content Server”

  1. Another very nice feature! Question about pagination performance. Do you retrieve all rows and just display the appropriate ones? Or do you try to manage the query so you only return what you need (using rownum for example)?

  2. Hi John: At first I tried this at the database level using ROWNUM but found it chaotic to implement cleanly in both Oracle and MSSQL. I dumped that solution in favour of a database cursor, which quickly zips to the starting position before returning the rows from that point on. For this I extended the default $LLIAPI.DBCursor in Content Server to do this faster without any unnecessary allocations. In the end I only allocate and return what I need. Please let me know if you’d like more information about the framework or have any other questions. Thanks for your comment!

  3. Fantastic and yeomanly in approach thereis so much OTcould have learned to adopt your style and programming I would very much like to try out the framework but alas work beckons one not to try anything outside You must know Chris Webster if not I will forward this link you guys need to connect

    • Thanks Appu: It’s been a change working at this higher level in Content Server. I can focus more on the solution rather than get wound up in the intricate technical details of Content Server.

 Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>