Skip to content

Commit 3331770

Browse files
authored
[REL-1066770] Add custom item list example (#3)
This example demonstrates a basic event handler that adds a custom item list to a layout. This slightly modifies the example listed on this page: https://platform.relativity.com/RelativityOne/Content/FormsAPI/Item_list_event_handlers.htm https://github.com/user-attachments/assets/dbef5fbd-457c-4df2-926c-4332e3fa3c5a
1 parent 76035b9 commit 3331770

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
(function(eventNames, convenienceApi) {
2+
const eventHandlers = {};
3+
const COLUMN_1_ID = 1000001;
4+
const COLUMN_2_ID = 1000002;
5+
6+
eventHandlers[eventNames.TRANSFORM_LAYOUT] = function(layoutData) {
7+
layoutData.push({
8+
Elements: [{
9+
"View": {
10+
"Name": "Test",
11+
"ArtifactID": 0, // Artifact ID of the view.
12+
"FieldsIds": [COLUMN_1_ID, COLUMN_2_ID], // Artifact IDs of the fields.
13+
"Sorts": [],
14+
"RenderLinks": true,
15+
"HasConditions": false,
16+
"GroupDefinitionFieldName": "",
17+
"QueryHint": "",
18+
ObjectTypeID: 0
19+
},
20+
"FieldCollection": [{
21+
AvfID: COLUMN_1_ID,
22+
"IsVisible": true,
23+
"ItemListType": "Text",
24+
"IsSortable": true,
25+
HeaderName: "Modified By"
26+
},
27+
{
28+
AvfID: COLUMN_2_ID,
29+
"IsVisible": true,
30+
"ItemListType": "Text",
31+
"IsSortable": true,
32+
HeaderName: "Modified On"
33+
}
34+
]
35+
}]
36+
});
37+
};
38+
39+
eventHandlers[eventNames.ITEM_LIST_MODIFY_ACTIONS] = function(itemListActionsApi, itemListView) {
40+
// Override default item list action bar buttons to show no buttons
41+
itemListActionsApi.initialize();
42+
43+
// Add an item list action bar button to refresh the item list
44+
const customAction = itemListActionsApi.addAction(convenienceApi.constants.ACTION_TYPES.NEW);
45+
customAction.title = "Refresh";
46+
customAction.action = function() {
47+
const historyItemListFieldId = self.fieldNameToFieldIdMap.get(HISTORY_ITEM_LIST_NAME);
48+
49+
convenienceApi.fieldHelper.getHtmlElement(historyItemListFieldId).then(function(itemListElement) {
50+
const refreshEvent = document.createEvent("Event");
51+
refreshEvent.initEvent("reloadItemListData", true, true);
52+
itemListElement.dispatchEvent(refreshEvent);
53+
});
54+
}
55+
56+
// Override item list data source
57+
itemListActionsApi.setCustomGetDataFunction(function(category, request) {
58+
// Create some example data to show in the item list with the current date.
59+
// That way the Modified On time will update to the current time when the item list refreshes.
60+
const currentDate = new Date();
61+
const exampleData = [
62+
{
63+
"ArtifactID": 1000010,
64+
"Modified By": "Test User",
65+
"Modified On": currentDate.toString()
66+
}, {
67+
"ArtifactID": 1000011,
68+
"Modified By": "Test User 2",
69+
"Modified On": currentDate.toString()
70+
}
71+
];
72+
73+
return {
74+
TotalCount: exampleData.length,
75+
Results: exampleData
76+
};
77+
});
78+
};
79+
80+
return eventHandlers;
81+
})(eventNames, convenienceApi);

examples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ For detailed instructions on how to build a Relativity Forms Javascript Event Ha
3535
* [Add a field to a layout programmatically](./JsEventHandlerExamples/transformLayout-addField.js)
3636
* [Remove a category](./JsEventHandlerExamples/multi-field-manipulation.js)
3737

38+
### Item List
39+
* [Adding a custom item list](./JsEventHandlerExamples/custom-item-list.js)
40+
3841
## Contributing
3942
If you have an example that you would like to contribute to our Relativity Forms Developer Community, please follow the steps in the [CONTRIBUTING.md](./CONTRIBUTING.md).

0 commit comments

Comments
 (0)