Showing posts with label Master-Detail. Show all posts
Showing posts with label Master-Detail. Show all posts

Monday, 21 January 2019

JET - master detail with ADF BC REST and pagination

JET: v6.0.0
Source: GitHub

Master detail view on the UI is something used often to showcase relational data. With Oracle JET, powered by ADF BC REST service, this becomes quite easy to achieve. However, it has to be mentioned that most of the hard work is done by the REST service. JET does not provide any out-of-box support for master-detail, you have to code a bit.

This article talks about a couple of approaches to this use-case. The first one is relatively faster, but works better on single child records. The second option is more robust as it handles multiple child records with pagination support.

To get started, we need to set the REST resource to support master-child relationship. The departments and employees are connected by a view link. The "departments" resource is updated to return child collection.

For the first approach, the department REST call is extended by an expand keyword. The expand keyword takes in the name of the child accessor, and this returns the child records in the response data. Without the expand parameter, only the master data is returned.

The JET model is updated to parse the EmployeesVO array from the response JSON.

When the department collection is built, the selection listener gets the current record and populates the ArrayTableDataSource observable with the EmployeesVO array. [Refer to my handling-table-selection-with-promise article for more details on extracting selection data].

The employees collection gets updated on department selection.

This approach is more suited when you want to display a single child record, as you get away with a single REST call to get your child record.

However, this approach has a downside! If your child accessor has many records, and you would want the power of JET's common model for pagination, this is not the way to go. Since this is one single REST call, the limit which is applied on the parent, is also applied on the child records. So if you have set 5 departments to be fetched at a time, it will also fetch 5 child employees (and not more!).

In order to achieve pagination support with common model, we need to create a URL of the following nature:

For example: /departments/50/child/EmployeesVO?limit=5&totalResults=true

Create a new instance of Employee common collection with this URL and set it on the ojTable's CollectionTableDataSource object.