Grid view
Last updated
Last updated
© 2024 UI Bakery
Grid view component serves for displaying the collection of items. By default, the grid view contains an image field and a caption, which can be replaced with the required components. If you need to create a custom layout, you can add the necessary components to the first list item. The added components are replicated for the other grid view items.
setPage(number)
navigates to a specific page
setPageSize(number)
sets the number of items displayed per page in a grid view
Triggers allow you to launch certain actions based on different events.
On Init
Calls for an action on component's initialization
On Page Change
Calls for an action when the grid page is changed
The grid view component supports both static and dynamic data.
To display the data dynamically from your action, refer to your action as {{actions. yourLoadDataAction. data}}
in the Data field of the grid component.
You can access any of the grid items by referencing it as {{item}}
, e.g. {{item.first_name}}
:
To reference the index of the item, use the {{index}} variable.
If you need to display checkbox/input components and monitor their values corresponding to the grid items, here is how you can do this:
Firstly, create a variable that will hold the list of items to be displayed in the grid:
Load the data into the variable. We will do this with the JavaScript action step. Each item must have a unique id for identification purposes at a later stage:
Notice how each item includes a selected
attribute - it will indicate whether the checkbox has been selected or not.
Next, connect the variable to the grid component and to the inner checkbox component with the {{item}}
variable - each {{item}}
represents a value from the assigned array variable.
Grid component:
Inner checkbox component:
Notice how we set the selected
property to the value
setting of the component. Now if we change the list
variable values - and set some item to be selected - this will be reflected on the ui:
Lastly, we need to track the "On Change" event of the checkbox and update its selected
value inside of the list
variable:
Assign a new action to the On Change trigger, in the trigger parameters - pass the id of the current grid item - this will indicate which checkbox has changed its value:
Now, we can complete this action with some JavaScript code to find the checked item and alternate its current value:
That's it! This way you will keep your grid input items in sync with the "data model" and can use this data to send all updated values to the server.
If you have a large dataset, you might want to use server-side pagination with a grid view component. Please refer to the guide below for setup: