top of page
Logo of top retool developers and retool agency

Opening a Modal from Table Row in Retool

Retool Modals are popup dialogs within Retool applications that can display information, collect user input, or present complex forms and interactive content. Modals are a crucial UI component in Retool that helps enhance the user experience by providing focused interaction without navigating away from the current page.


You can follow the comprehensive guidance on the Retool modal in this article and learn how it can be used in Retool for your projects.


Key Features and Common Use Cases


Modal from Table Row in Retool

Key Features of Retool Modals:

  1. Popup Dialogs: Modals appear as overlay windows above the main application content, drawing user attention to important information or actions.

  2. User Interaction: They can contain forms, buttons, text, images, and other interactive elements, allowing users to perform tasks directly within the modal.

  3. Customizable: Modals in Retool can be customized in size, content, and behavior, making them versatile for various use cases.

  4. State Management: You can manage the state within modals, such as input values and form submissions, using Retool's state variables and JavaScript methods.

  5. Conditional Display: Modals can be triggered conditionally based on user actions, such as button clicks or specific events within the application.


Common Use Cases for Retool Modals:

  1. Form Submission: Collect user inputs through forms presented in a modal, which can then be processed or submitted to a backend service.

  2. Confirmation Dialogs: Display confirmation dialogs for critical actions, such as deleting a record or submitting sensitive information.

  3. Detailed Information: Show additional details or extended information about an item without navigating away from the main page.

  4. Multi-step Processes: Implement multi-step workflows or wizards within modals, guiding users through a sequence of actions.


Setting Up the Modal in Retool


To effectively utilize modals in your Retool application, follow these steps to set up and configure the modal component:


1. Insert a Modal Component in the Retool App

  1. Open Your Retool App:

  • Navigate to the Retool app where you want to add the modal.

  1. Add the Modal Component:

  • Drag and drop the Modal component from the component library into your workspace.


2. Ensure the Modal’s Hidden Attribute is Set to True

You need to set its hidden attribute to true to ensure the modal does not appear by default when the app loads.

  1. Select the Modal Component:

  • Click on the Modal component to open its properties panel.

  1. Set Hidden Attribute:

  • Find the property labeled "Hidden" and set it to true. This ensures that the modal is not visible when the app initially loads. Otherwise, dynamically control whether the modal is hidden. This property can be set via the setHidden API in Event Handlers or JavaScript queries.

                        modal.setHidden(true);


3. Hide the Modal's Initial Button (If Using One)

If a button triggers your modal, you might want to hide this button after the modal is set up, depending on your use case.

  1. Select the Trigger Button:

  • Click on the button that you use to trigger the modal.

  1. Set Hidden Attribute:

  • Set the button's "Hidden" attribute to true if you do not want it visible on the user interface. Alternatively, you can control its visibility dynamically based on certain conditions by using the ‘setHidden’ function.

                        button.setHidden(true);


You can also learn more about how Retool assisted in efficient lead generation and discovery for Speakeasy. Start using Retool for your workflows by partnering with Toolpioneers.


Using Event Handling in the Table Component to Open a Modal

Event handling in the table component is a powerful feature in Retool that allows you to trigger actions based on user interactions with table rows or cells. 

This section will explain how to set up an event handler to open a modal and configure an action button to execute a JavaScript query on click.


Overview of the Function

In the example below, we will focus on setting up an event handler for a table component that triggers a modal to open when a user interacts with a specific row or button within the table. This setup enhances the user experience by providing a seamless way to display additional information or perform actions without navigating away from the current view.


Step-by-Step Guide


retool modal

1. Set Up an Event Handler in the Table Component to Open the Modal

Step 1: Select the Table Component

  • Navigate to the table component in your Retool app where you want to add the event handler.

Step 2: Configure the Event Handler

  • In the table's settings, go to the "Events" section.

  • Add an event handler for the desired event (e.g., row click, cell click).

Step 3: Define the Event Action

  • Set the event action to open the modal. This can be done by executing a JavaScript function that opens the modal.

function tableOnRowClick((row) => {

    // Capture the row data or any necessary details

    const rowDataObject = table.selectedRow;

    // Open the modal

    modal.open();

    // Optionally, populate modal form with row data

    modalForm.setData(rowDataObject);

});



2. Or Configure the Action Button to Execute a JavaScript Query on Click

Step 1: Add a Row Action Button and Set it up on Table Properties Section

  • Configure the action button to trigger a JavaScript query when clicked.

Step 2: Write the JavaScript Query

  • Define the JavaScript function that the button will execute. This function can perform necessary actions, such as opening a modal or fetching additional data.

// JavaScript to be executed on button click

function actionButtonOnClick((row) => {

    // Capture the row data or any necessary details

    const rowDataObject = table.selectedRow;

    // Execute a query or open a modal

    modal.open();

    modalForm.setData(rowDataObject);

    // Optionally, trigger other actions or queries

    additionalQuery.trigger({ additionalScope: { id: rowData.id } });

});


Implementing these techniques can enhance the interactivity and functionality of your Retool applications, making them more responsive to user actions and capable of handling complex workflows efficiently. 


Also, you can explore more on how Retool aided in building of custom event management app. Wondering how to start using Retool immediately? It's simple: get in touch with Toolpioneers, and we will guide you through everything you require from the beginning to post-deployment care and support.


Populating the Modal with Row Data


Populating the modal with row data in Retool involves dynamically displaying and potentially editing data from a selected row in a table within a modal dialog. This technique leverages Retool's ability to reference specific data fields using table properties, ensuring that the modal shows relevant and specific information based on user interactions with the table.

The primary purpose of populating a modal with row data is to enhance the user experience by providing a focused and detailed view of a selected item without navigating away from the main interface. 


1. Insert Components into the Modal to Display the Selected Row's Data

Step 1: Add Components to the Modal

  • Open the modal component in your Retool app.

  • Insert components such as text fields, labels, input boxes, or other relevant UI elements to display the row data.

  • For example, add a text component to display a user’s name or an input component for editing a field.

Step 2: Configure Each Component

  • Set up each component to display data dynamically. You will bind these components to the data from the selected row in the table.

Example:

  • Add a text component to display a user’s name:javascript

           <Text>Username: {{table.selectedRow.username}}</Text>

  • Add an input component for editing a user’s email

           <Input value="{{table.selectedRow.email}}" />


2. Reference Table Properties


Like {{table.selectedRow.fieldName}} in the Modal Components


Step 1: Access Table Properties

  • Use the double curly braces {{ }} syntax to reference the table's properties within the modal components. This allows you to access the data from the selected row dynamically.

Step 2: Bind Table Data to Modal Components

  • For each component within the modal, bind it to the appropriate field from the selected row’s data.

  • You can reference any field from the table’s selected row using the format {{table.selectedRow.fieldName}}.

Examples:

  • Displaying an Order Number

           <Text>Order Number: {{table.selectedRow.orderNumber}}</Text>


By following these steps, you can enhance the interactivity of your Retool application, making it easier for users to interact with and manage data directly from the modal. This setup is handy for displaying detailed information or providing streamlined edit capabilities for table rows.


Handling a single row and multiple rows differs significantly. Don't worry; you can follow the provided guidance, including examples, to manage complex multiple rows efficiently.


Handling Multiple Selected Rows in Retool


To handle multiple selected rows in Retool and pass their data to a modal, you need to use a different approach compared to handling a single selected row. Here’s a guide on how to achieve this:


1. Question: How do I pass multiple selected rows' data to the modal?

Passing data from multiple selected rows to a modal involves creating a custom JavaScript query that can handle and process the data from all selected rows. This allows you to display or manipulate multiple rows of data within the modal.


2. Using {{table.selectedRow}} for Single Row Data

For a Single Row:

  • You can use the {{table.selectedRow}} syntax to display data for a single selected row.

  • This is straightforward and works well for scenarios where only one row is selected.

Example:

<Text>Mobile no. : {{table.selectedRow.mobile_number}}</Text>


3. Create a Custom JavaScript Query to Handle Multiple Selected Rows

For Multiple Rows:

  • You must process an array of selected rows when multiple rows are selected.

  • Create a custom JavaScript query to gather and pass the data from multiple selected rows to the modal.

Steps:

  1. Select the Table Component:

  • Ensure your table allows multiple row selection by setting the "Allow multi-selection" property to true.

  1. Create a Custom JavaScript Query:

  • Write a JavaScript query that gathers data from all selected rows and passes it to the modal.

Example Query:

// JavaScript query to handle multiple selected rows

const selectedRows = table.selectedRows


// Open the modal


// Pass the selected rows' data to a table in the modal

modalTable.setData( selectedRows );


// Optionally, process or display the data in the modal in the console

selectedRows.forEach(row => {

    // Example: Display each selected row's username in the console

    console.log(`Username: ${row.username}`);

});

Implementing these techniques ensures that your Retool application can efficiently handle multiple selected rows, providing a better user experience and more robust functionality.

Now, you can explore the possible methods in the custom javascript queries to handle multiple selected rows in a table.


Alternative Methods for Handling Multiple Modals in Retool


When dealing with multiple modals in a Retool application, the interface can become cluttered and difficult to manage. Here are some alternative methods to handle multiple modals more efficiently:


1. Using a Custom Column Set to Type Modal


A custom Button column set to show modal on click allows you to embed modal triggers directly within a table column. This approach simplifies the management of multiple modals by making it easier to trigger and manage modals directly from table rows.


Steps to Implement:

  1. Add a Custom Button Column:

  • In your table component, add a custom button column

  1. Set Column Type to Modal:

  • Configure the button column and set the event handler for on click to show the modal. This will make each cell in this column a button that triggers a modal.

  1. Define Modal Content:

  • Set up the modal content to display the relevant data from the selected row.


2. Community Suggestion: Use the Drawer Component as an Alternative


The Drawer component is an alternative to modals that slide in from the screen's side. It offers a similar functionality to modals but provides a different user experience and layout.

The Drawer component is useful for managing multiple detail views without the overlapping and stacking issues that can arise with multiple modals. Drawers offer a more spacious and organized way to present detailed information.


Steps to Implement:

  1. Add a Drawer Component:

  • In your Retool app, add a Drawer component to your workspace.

  1. Configure Drawer Content:

  • Set up the content inside the Drawer to display data from the selected row.

  1. Trigger the Drawer:

  • Use an action, such as a button click in a table row, to open the Drawer and pass the relevant data.

Example:

// Action script to open the Drawer with selected row data

function tableOnRowClick((row) => {

    const rowDataObject = table.selectedRow

    drawer.open();

    drawerForm.setData(rowDataObect);

});

By implementing these alternative methods, you can efficiently manage multiple detail views in your Retool application, ensuring a cleaner and more user-friendly interface.



Conclusion


Retool modals are essential for enhancing user interaction, offering customizable and dynamic interfaces for various use cases such as form submissions, confirmation dialogs, and multi-step processes. Setting up and configuring modals in Retool is straightforward, allowing seamless integration and efficient workflows.

Toolpioneers is dedicated to helping you maximize Retool's potential. Our expertise ensures you can build powerful applications tailored to your needs.

Ready to enhance your Retool applications? Contact Toolpioneers today and transform your ideas into reality with our comprehensive support and expert solutions.

bottom of page