Add a custom item list to a layout

The following page explains how to add a custom item list to a layout in the Relativity Forms.

Adding a new item list & view information

The transformLayout event handler allows you to modify the layout information before it is rendered in the browser. In the code sample below, we add a handler that appends a new category to the user-selected layout, in order to show an item list called "History". To do that, let's append a single-category element containing another element with a View definition. At a minimum, the View definition needs to provide a FieldCollection detailing what fields are in the list. For now, let's define two columns for this layout detailing which user modified it, and when it was modified. Take note how we're following the same format of information as a View defined in Relativity - the View.FieldsIds array values correspond with the FieldCollection[n].AvfID values. The FieldCollection[n].HeaderName values decide what is shown as the column title in the item list.

As a result of our above configuration, the event handler appends this item list to the form:

  • No FilterType is defined in the FieldCollection, so this item list does not show any filters.
  • No IsSortable value is defined in the FieldCollection, so this item list does not support clicking on column titles to apply sorting.
  • No custom data source is defined, so the Item List is using Relativity Form's built in behavior to use Object Manager to query for data. Naturally, that is failing.

Overriding default action bar buttons

In order to restrict the default application behavior of adding action bar buttons, we need to call the itemListActionBarApi.initialize() method in the itemListModifyActions event handler, as illustrated below.

Calling an API to get Item list data

Now that we are able to generate a non-errored item list, let's call the Audit API to get real information to populate in the item list. Let's add this API call to our custom "get data" function. Please note that we're now returning a promise for the data, instead of an object, in our custom function.

Now we can see audit data in the item list:

Notice that the 'Modified On' dates are showing as plain text. We want them formatted correctly as dates. We can do that by defining the field as a date field.

Modifying the view to add field type information

Let's go back to the transformLayout event handler. In the FieldCollection array we defined, we'll need to add a FieldTypeID value and a FormatString value. Let's add a FieldTypeID value of "2", which corresponds to the Date field type, and since we want to show both date and time, lets set a FormatString value of "g".

Now we see the 'Modified On' values formatted correctly as date and times:

Turning on sorting

The business wants the user to be able to sort the list on the value of 'Modified On' so that they can easily see the earliest and most recent updates to the object. This requires two small changes to our current setup:

  • transformLayout event handler must define the 'Modified On' column as sortable.
  • The custom "get data" function defined in itemListModifyActions takes the applied sorts in the list and includes that information in the request to the Audit API.

Now the column sorting control is enabled in the item list, and correctly applies the sort value to the retrieved audit data shown in the list:

Enable filtering

The business wants the user to be able to filter the 'Modified On' column in order to see only data from a certain time period. This requires two updates:

  • The transformLayout event handler must define the 'Modified On' column as filterable. This can be done by adding the FieldTypeID, FilterType, FormatString, and IsFilterable attributes to the column definition in the FieldCollection array.
  • The custom "get data" function defined in itemListModifyActions must take any applied filters and apply them to the data.

The custom "get data" function defined in itemListModifyActions provides filter data in the request object that it passes to the function when it executes. The request object, in turn, contains a filter object and a condition object, both of which contain data on the requested filter.

Now the filter control is enabled and it applies to the example data. See below an example of an item list that's filtering between 7/10/2019 and 8/10/2019.

Add custom action buttons

You can use the Item List Actions API to add a custom button to the item list by utilizing the addAction method. The method returns the Action object for the button, which can be used to customize the button further. The Action object has a title field, which can be used to customize the title of the button, and an action field that can be assigned a specific function to be executed when the button is clicked.

Now that we've modified the above custom function, we can see a new Create button in the item list action bar below. The newly added button will open a Create modal when clicked.

Custom views

In previous examples on this page, we have shown one way to define a custom view by pushing it to the Layout data in the transformLayout  event handler. Then, we defined a custom data source in the itemListModifyActions event handler to override Relativity Form's built in way of pulling data. Then, we overrode the default action bar buttons in the itemListModifyActions event handler by calling the itemListActionBarApi.initialize() method.

There are, however, a few different ways to define a custom view. One such way is to create a view in Relativity, then add a reference to it in the transformLayout event handler. See Creating a View for additional information.

In this example, 1039369 is the Artifact ID of the new View. The Artifact ID should be listed on the ArtifactID property of the View object, and can be found on the Views tab in your Workspace. If you need to modify the Views tab to get the Artifact ID, a detailed explanation can be found here.

1038304 and 1038305 are the Artifact IDs of the two fields in the new View. These Artifact IDs should be listed in the FieldsIds array of the View object as shown above. They should also be listed in the AvfID and ArtifactID properties of the FieldCollection array as shown above. The Artifact IDs can be found on the Fields tab of your Workspace by searching for the Fields of your Object Type. If you need to modify the Fields tab to get the Artifact ID, a detailed explanation can be found here.

1000042 is the Artifact Type ID of the Object Type to be displayed. It should be listed on the ObjectTypeID property of the View object as shown above. The Artifact Type ID can be found in the Object Type tab in your Workspace. If you need to modify the Object Type tab to get the Artifact Type ID, a detailed explanation can be found here.

Documentation for the fields in the layoutData can be found here.

Refreshing the item list

To refresh the item list, we can dispatch areloadItemListDataevent to the item list. We can build off of what we did in the Custom Views section to create a button that will refresh the item list.

Notice the HeaderName values of the FieldCollection array were changed in the transformLayout event handler to match the example data in the itemListModifyActions event handler. It may be helpful to note that the most critical aspect of the above code sample is where the Refresh button is defined in the itemListModifyActions event handler. This code defines an action for the button that dispatches a reloadItemListData event. 

It creates a row with the current date and time to put in the item list. That way, the Modified On time will update every time the item list refreshes.

Return to top of the page
Feedback