Font Size:
Ask Joget AI

Grid Integration & Data Management

Introduction

Explore how to seamlessly integrate a grid into your application and efficiently manage form data using the Bean Shell Form Binder. This comprehensive guide covers loading and storing data within the grid, empowering you to optimize data management within your Joget applications.

Add a grid to your application

Establishing a clear relationship between different forms is important when designing complex applications like a leave management system in Joget. Here’s how to seamlessly integrate a grid that links a single leave application to multiple leave details.

Understanding relationships

In applications that involve multiple forms, understanding the relationships between these forms is important. The example provided here demonstrates the relationship between a primary form and a secondary form:

  • Primary Form: leaveApplication
  • Secondary Form: leaveDetails
  • Relationship: Each leave application encompasses various details, forming a one-to-many relationship.

Configure the grid

Setting up your grid involves two main steps:

Storing data

By default, the system stores data in JSON format directly in the leaveApplication parent table, ensuring quick access and integrity.

Storing in a separate table

For enhanced flexibility, you might opt to store entries in a separate table:

  • Binder Configuration: Employ the Multirow Form Binder as the Store Binder and Load Binder.
  • Parent ID Setup: Create a dedicated field to maintain the parent ID in the chosen table. This field ensures each entry in the grid is linked to its respective leave application.
  • Field Consistency: Ensuring that each "value" in the grid's properties precisely matches the corresponding fields in your table is critical.

Practical example

Let’s visualize how data appears in our tables:

  • Parent Table (leave_application):

    Primary Key Name ...
    1550 David ...
  • Child Table (leave_details):

    Primary Key Foreign Key Other Fields
    800 1550 ...
    801 1550 ...
    802 1550 ...

Each detail record has a unique identifier that is distinct and traceable to its leave application.

Load & store form grid data using bean shell form data store

Learn how to load and store data in a Form Grid using the Bean Shell Form Binder within Joget. This functionality is essential for efficiently managing and interacting with data across multiple database tables. It provides a practical approach for developers and administrators looking to enhance data operations in their applications.

Load data store using Bean Shell form data store

Import Necessary Classes and Establish Connection:

import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.dao.FormDataDao;
import org.joget.apps.form.model.FormRowSet;


FormRowSet rows = new FormRowSet();
rows.setMultiRow(true);


if (primaryKey != null && !primaryKey.isEmpty()) {
    FormDataDao dao = (FormDataDao) AppUtil.getApplicationContext().getBean("formDataDao");
    FormRowSet result = dao.find("leave_details", "leave_details",
            "WHERE e.customProperties.parent_id = ?", new Object[]{ primaryKey },
            "dateCreated", false, null, null);
    if (result != null) {
        rows.addAll(result);
    }
}
return rows;

Store data store using Bean Shell form data store

Save Grid Rows and Close Connections:

import java.util.ArrayList;
import java.util.List;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.dao.FormDataDao;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.commons.util.UuidGenerator;


String formDefId = "leave_details";
String table = "leave_details";
String parentId = formData.getPrimaryKeyValue();
FormDataDao dao = (FormDataDao) AppUtil.getApplicationContext().getBean("formDataDao");


// Delete rows that were removed in the grid
FormRowSet existing = dao.find(formDefId, table,
"WHERE e.customProperties.parent_id = ?", new Object[]{ parentId }, null, null, null, null);
List keep = new ArrayList();
for (FormRow r : rows) {
    if (r.getId() != null && !r.getId().isEmpty()) keep.add(r.getId());
}
List toDelete = new ArrayList();
if (existing != null) {
    for (FormRow r : existing) {
        if (!keep.contains(r.getId())) toDelete.add(r.getId());
    }
}
if (!toDelete.isEmpty()) {
    dao.delete(formDefId, table, (String[]) toDelete.toArray(new String[0]));
}


for (FormRow r : rows) {
    if (r.getId() == null || r.getId().isEmpty()) r.setId(UuidGenerator.getInstance().getUuid());
    r.setProperty("parent_id", parentId);
}
dao.saveOrUpdate(formDefId, table, rows);
return rows;

Grid design

The correct grid design should look like this:

Example of a Simple Load Binder BeanShell Script

import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;

FormRowSet f = new FormRowSet();
f.setMultiRow(true);

FormRow r1 = new FormRow();
r1.put("gridColumn1", "your_value");
r1.put("gridColumn2", "your_value");
r1.put("gridColumn3", "your_value");
f.add(r1);

FormRow r2 = new FormRow();
r2.put("gridColumn1", "your_value");
r2.put("gridColumn2", "your_value");
r2.put("gridColumn3", "your_value");
f.add(r2);

return f;

To further enhance your understanding and capabilities with Joget, here are some valuable resources that delve deeper into specific functionalities. Whether you want to refine your skills in managing form grids or explore the intricacies of using Bean Shell for data operations.

Download sample app

Download the sample app for Grid Integration & Data Management
Created by Julieth Last modified by Nur Baizura Badrul Sham on Oct 29, 2026