Create an Editable Table
You can create an editable table that allows users to edit multiple existing rows before they submit all their changes in one transaction to the backend service.
This implementation of an editable table uses the Buffering Data Provider with a Service Data Provider (SDP). The Buffering Data Provider is a wrapper that provides buffering for an underlying data provider, so that edits can be committed to the data source later on. The underlying data provider (Service Data Provider, in this case) is responsible for fetching data, and the Buffering Data Provider merges any buffered edits with the underlying data so they appear as a unified set of data.
Here’s how you can create a table that displays editable rows of employees. All changes are stored in a buffer until the user clicks a Save button, at which time a REST call posts the changes to the backend service. The example used here follows the Batch Editable Table (BDP) recipe in the Visual Builder Cookbook, which demonstrates additional functionality, such as how to implement validation and create new rows.
-
Add a table to your page and connect it to data using the Add Data quick start. The quick start creates a variable that is automatically bound to the table component. Because this variable is based on the Service Data Provider type, you need to create a variable based on the Buffering Data Provider type and set up your table to reference the new variable.
-
Drag and drop a table component to your page, then add data to it using the Add Data quick start.
-
Create a variable (for example,
employeesBDP) based on the Buffering Data Provider type. In the newly created variable’s Properties pane, map thedataProviderConstructor Parameter to theemployeeListSDP:

-
In the table’s Data tab, change the
dataproperty to point to[[ $variables.employeesBDP.instance ]], instead ofemployeeListSDP.

-
-
Create event listeners and action chains to handle the table’s edit events and make the table editable.
-
Create a custom type from your endpoint (for example, the
EmployeeTypetype based on theGET /Employee/{Employee_Id}endpoint), then create a page variable namedcurrentRowBufferthat is assigned to the custom type. -
Now add an
ojBeforeRowEditevent listener to the table, then in theTableBeforeRowEditChain, add an Assign Variable action with the current row data (rowData) assigned to thecurrentRowBufferpage variable.

Description of the illustration assignvar-ojbeforerowedit1.png
-
Add an
ojBeforeRowEditEndevent listener to the table, then in theTableBeforeRowEditEndaction chain, add two new Parameters as input parameters:-
currentRowBufferof typeEmployeeType

Description of the illustration ojbeforeroweditend-add-params1.png
-
eventof typeAny
-
-
To map these two new parameters, open the Event Listeners tab, select the TableBeforeRowEditEnd action chain under the tableBeforeRowEditEnd event. In the action chain’s Properties pane, map the new parameters to
$variables.currentRowBufferand$event, respectively.

Description of the illustration tablebeforeroweditend-mapping1.png
-
In the
TableBeforeRowEditEndaction chain, add an If action and test if thecancelEditparameter isfalse. Iffalse, changes need to be stored into theemployeesBDP.Storing changes is implemented using a Call Variable action for variable
employeesBDPand functionupdateItemwith parameters:{ metadata: { key: rowKey}, data: currentRowBuffer}
Description of the illustration tablebeforeroweditend-actionchain-callvar.png
-
Both the
ojBeforeRowEditandojBeforeRowEditEndevents must have asynchronous handling enabled for editable table functionality to work. To do this:-
Switch to the Event Listeners editor and select the tableBeforeRowEdit event under Component Event Listeners.
-
In the event listener’s Properties pane, toggle Async Handling from Disabled (default) to Enabled.
-
Repeat the steps for the tableBeforeRowEditEnd event.
-
-
In the table’s properties, set Edit Mode to Row Edit (if the option isn’t already selected).
-
Enhance table cells to make them editable:
-
Drag and drop a Text component onto the first table column which needs to be editable. This generates a cell template for the column.
-
In the Structure view, right-click the Bind Text node and select Surround and If to generate a condition for when to render the text component. Set the If condition to
[[$current.mode === 'navigation']]. When the table row is in read-only mode navigation, the text component will render the column value. -
Drop an Input Text (or any other component) into the same cell template as the Bind Text node and wrap it again in an If condition, but this time set the condition to
[[$current.mode === 'edit']]to show an editable input text component when the table row is in edit mode. -
Remove the Input Text component’s Label Hint and ReadOnly properties. Bind the Value property in the Data tab to the corresponding property from
currentRowBuffer. For example,{{ $variables.currentRowBuffer.firstName }}.
Use similar steps to make the other table columns editable.
-
-
-
Track and save changes to the table. Saving changes involves collecting them from the Buffering Data Provider instance, marking changes as being submitted, creating a single batch REST Call payload to store all changes in one transaction, and finally marking changed items in the Buffering Data Provider as submitted.
-
Drag a button and drop it above the table on the page. Change the Label to Save in the button’s properties.
-
In the button’s Events tab, add an event listener for the On ‘ojAction’ event and rename the corresponding action chain as SubmitChanges.
-
In the SubmitChanges action chain, add supporting JavaScript functions:
-
The
createBatchPayloadfunction to generate the payload with all changes. All changes stored in the Buffering Data Provider are accessed using the API callgetSubmittableItems. -
The
setStatusTofunction to set Buffering Data Provider items tosubmitting,submitted, orunsubmittedstates. The Buffering Data Provider requires an edit item’s status to be set, via thesetItemStatusAPI call, before the change is committed to the data source.
See the batch editable table recipe in the cookbook for sample code.
-
-
Using these functions, you can build your action chain to change state, save data, and handle error states. See the batch editable table recipe in the cookbook for sample code.
-