Skip to content

Commit a434ead

Browse files
Openblocks-docsgitbook-bot
Openblocks-docs
authored andcommitted
GITBOOK-128: Update List View and JS query
1 parent 70f6af9 commit a434ead

26 files changed

+105
-61
lines changed

‎docs/.gitbook/assets/list-view-1.PNG

76.4 KB
Loading

‎docs/.gitbook/assets/list-view-10.png

202 KB
Loading

‎docs/.gitbook/assets/list-view-11.png

76.5 KB
Loading

‎docs/.gitbook/assets/list-view-2.PNG

225 KB
Loading

‎docs/.gitbook/assets/list-view-3.png

154 KB
Loading

‎docs/.gitbook/assets/list-view-4.png

177 KB
Loading

‎docs/.gitbook/assets/list-view-5.png

134 KB
Loading

‎docs/.gitbook/assets/list-view-6.png

315 KB
Loading

‎docs/.gitbook/assets/list-view-7.png

18.6 KB
Loading

‎docs/.gitbook/assets/list-view-8.png

67.5 KB
Loading

‎docs/.gitbook/assets/list-view-9.png

84.5 KB
Loading

‎docs/build-apps/component-guides/list-view.md

+87-35
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,73 @@ description: >-
77

88
# List View
99

10-
The following is a demo of **List View**, which displays part of BEST BOOKS OF 2021 from [Goodreads](https://www.goodreads.com/choiceawards/best-books-2021):
10+
The component **List View** displays rows of data. Similar to Form, Modal, and Drawer, it is also a container-like component that can hold other components or modules. For list viewing data, you first bind the data to a **List View** component and configure the naming rules for the items. Then, you design the display of the first row by dragging and dropping components, and this layout will be applied to all items within this component.
11+
12+
The following is a demo of **List View**, displaying part of BEST BOOKS OF 2021 from [Goodreads](https://www.goodreads.com/choiceawards/best-books-2021):
1113

1214
<figure><img src="../../.gitbook/assets/listview-1.gif" alt=""><figcaption></figcaption></figure>
1315

14-
Drag and drop **List View** onto the canvas. The list has three rows by default, and in each row there is an **Image** and a **Text** component. You only need to change properties of the first row, and the same settings are applied to the other rows automatically.
16+
Drag and drop **List View** onto the canvas. Each item contains an **Image**, a **Text** and a **Rating** component. You can update the exhibition of the whole **List View** component by configuring the layout of the first entry.
1517

16-
<figure><img src="../../.gitbook/assets/listview-2.png" alt=""><figcaption></figcaption></figure>
18+
Click the **Image** component, you see the defaulted image source.
1719

18-
For example, you can bind a static URL address to the **Image** component for image display; and because that URL address is static, the same image shows up in all rows.
20+
<figure><img src="../../.gitbook/assets/list-view-1.PNG" alt=""><figcaption></figcaption></figure>
1921

20-
<figure><img src="../../.gitbook/assets/listview-3.png" alt=""><figcaption></figcaption></figure>
22+
The **List View** component retrieves data from a JSON array of objects and displays an **Image**, a **Text** and a **Rating** component for each entry. You can also pass query results to a **List View**.
2123

22-
To display data or images in a dynamic way, [#use-dynamic-variable-i](list-view.md#use-dynamic-variable-i "mention").
24+
<figure><img src="../../.gitbook/assets/list-view-2.PNG" alt=""><figcaption></figcaption></figure>
2325

24-
## Set the number of list rows
26+
## Bind data
2527

26-
You can set the number of list rows in a static way by inputting a number, or bind it to dynamic query result.
28+
The data of a **List View** component accepts two types of values: number and array.
2729

28-
<figure><img src="../../.gitbook/assets/listview-4.png" alt=""><figcaption></figcaption></figure>
30+
* Number: Numbers are processed as row count and no valid data is passed into the **List View** component.
31+
* Array: The length of an array is passed as row count and each entry in the array is processed as a JS object in JSON format, corresponding to a row in the **List View** component. For example, the following data contains two rows of data, each containing four fields: `rate`, `title`, `url`, and `cover`.&#x20;
2932

30-
For example, to display all the fictions from the table `fiction` in **List View**, set the number of rows in the following steps:
33+
```json
34+
[
35+
{
36+
"rate": "9.2",
37+
"title": "The Shawshank Redemption",
38+
"url": "https://www.imdb.com/title/tt0111161/",
39+
"cover": "https://m.media-amazon.com/images/M/MV5BMDFkYTc0MGEtZmNhMC00ZDIzLWFmNTEtODM1ZmRlYWMwMWFmXkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_UY67_CR0,0,45,67_AL_.jpg"
40+
},
41+
{
42+
"rate": "9.2",
43+
"title": "The Godfather",
44+
"url": "https://www.imdb.com/title/tt0068646/",
45+
"cover": "https://m.media-amazon.com/images/M/MV5BM2MyNjYxNmUtYTAwNi00MTYxLWJmNWYtYzZlODY3ZTk3OTFlXkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_UY67_CR1,0,45,67_AL_.jpg"
46+
}
47+
]
48+
```
3149

32-
1. Create a query to count the items of your data—for example, `countAllFictions`.
33-
2. Write the following code for the query:&#x20;
50+
You can view the detailed data about the **List View** component, its items, the properties, etc., in the data browser.
3451

35-
```sql
36-
select count(*) from fiction
37-
```
52+
<figure><img src="../../.gitbook/assets/list-view-3.png" alt=""><figcaption></figcaption></figure>
3853

39-
&#x20; 3\. Reference the query result in **Number of rows** via the code:&#x20;
54+
<figure><img src="../../.gitbook/assets/list-view-4.png" alt=""><figcaption></figcaption></figure>
4055

41-
```javascript
42-
{{countAllFictions.data[0].count}}
43-
```
56+
## Display data in inside components
4457

45-
## Use dynamic variable i
58+
After binding valid data to **List View** component and designing its inside components, you can add data to these components. **List View** supports local variables `currentItem` and `i`. Notice that you only need to change data of the first row, and the same settings are applied to the other rows automatically.
4659

47-
To bind the display data in a dynamic way, use the dynamic variable `i`. For example, if you want to display fiction book names in **Text** components, then you bind the value of `book_name` to `text1` in the following steps:
60+
{% hint style="info" %}
61+
You can bind a static URL address to the **Image** component for image display; and because that URL address is static, the same image shows up in all rows.
62+
{% endhint %}
4863

49-
1. Create a query to get all the needed data—for example, `getAllFictions`:
64+
<figure><img src="../../.gitbook/assets/listview-3.png" alt=""><figcaption></figcaption></figure>
5065

51-
```sql
52-
select * from fiction
53-
```
66+
## Name items
5467

55-
&#x20; 2\. Reference the query result in the value of `text1`:
68+
You can set the item index names and item data names. This is useful when embedding a list in another list. For example, you can set the index of one list as `i`, and the inner nested `j` to avoid naming conflict.
69+
70+
<figure><img src="../../.gitbook/assets/list-view-5.png" alt=""><figcaption></figcaption></figure>
71+
72+
### Item index name
73+
74+
By default, item index is named as`i`, referring to the index of list data and starting from zero. Besides using `i` as numbers, you can also use `i` to dynamically access data from query results.
75+
76+
For example, to access the `book_name` field from table `fiction` in the **Text** component, write the following code.
5677

5778
```javascript
5879
{{getAllFictions.data[i].book_name}}
@@ -62,21 +83,52 @@ Then you can see the fiction book names displayed in **List View** by index orde
6283

6384
<figure><img src="../../.gitbook/assets/listview-5.png" alt=""><figcaption></figcaption></figure>
6485

65-
Similarly, to display book covers, reference the query result in the value of `image1`:
86+
### Item data name
87+
88+
By default, you can reference the value of each item within a list using variable `currentItem`. For example, to display a serial number plus book name, write the following code in `text1` value.
6689

6790
```javascript
68-
{{getAllFictions.data[i].cover}}
91+
{{i+1}}. {{currentItem.book_name}}
6992
```
7093

71-
<figure><img src="../../.gitbook/assets/listview-6.png" alt=""><figcaption></figcaption></figure>
94+
<figure><img src="../../.gitbook/assets/list-view-6.png" alt=""><figcaption></figcaption></figure>
95+
96+
{% hint style="info" %}
97+
Circular dependency errors occur when you reference the data of a row by `listView.items[i]` from a component inside a **List View** component. It is recommended to use such reference only outside the list.
98+
{% endhint %}
99+
100+
## Pagination
72101

73-
To display more data such as author names and book introductions, drag in **Text** components and then reference the query result:
102+
### Quick jumper
103+
104+
Toggle "Show quick jumper" or set its value to `true` to allow your users quickly jump to the specified page.
105+
106+
<figure><img src="../../.gitbook/assets/list-view-7.png" alt=""><figcaption></figcaption></figure>
107+
108+
### Page size
109+
110+
You can configure whether to allow your users to customize how many items to be displayed on a single page by enabling or disabling the "Show size changer button" or set its value in JS. When disabled, you can set the default page size.
111+
112+
<figure><img src="../../.gitbook/assets/list-view-8.png" alt=""><figcaption></figcaption></figure>
113+
114+
If enabled, you can configure several page sizes for your users to select.
115+
116+
<figure><img src="../../.gitbook/assets/list-view-9.png" alt=""><figcaption></figcaption></figure>
117+
118+
### Total row count
119+
120+
By default, the total row count of a **List View** component is the number of current data items. You can also insert a value from a query. For example, `{{query1.data[0].count}}`.
121+
122+
## Reference List View items outside
123+
124+
**List View** supports exposing data of inside components with **Items** field. You can inspect the **Data Browser** in the left pane.
125+
126+
<figure><img src="../../.gitbook/assets/list-view-10.png" alt=""><figcaption></figcaption></figure>
127+
128+
For example, drag an **Input** component into **List View**, and then you can reference the value of the **Rating** component in components outside the **List View** by the following code.
74129

75130
```javascript
76-
{{getAllFictions.data[i].author_name}}
77-
{{getAllFictions.data[i].intro}}
131+
{{listView1.items[0].rating1.value}}
78132
```
79133

80-
<figure><img src="../../.gitbook/assets/listview-7.png" alt=""><figcaption></figcaption></figure>
81-
82-
<figure><img src="../../.gitbook/assets/listview-8.png" alt=""><figcaption></figcaption></figure>
134+
<figure><img src="../../.gitbook/assets/list-view-11.png" alt=""><figcaption></figcaption></figure>

‎docs/build-apps/design-app-ui/style-theme-and-usability.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Workspace admins have access to theme settings. On Openblocks homepage, go to **
3030

3131
Preview the real-time theme effect on the right.
3232

33-
<figure><img src="../../.gitbook/assets/style-theme-usability-6 (1).PNG" alt=""><figcaption></figcaption></figure>
33+
<figure><img src="../../.gitbook/assets/style-theme-usability-6.PNG" alt=""><figcaption></figcaption></figure>
3434

3535
### Apply a theme
3636

‎docs/build-apps/event-handlers.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In Openblocks, event handlers are responsible for collecting and processing events from components and queries, and executing subsequent actions. For example, for a **Button** component, you can add an event handler to trigger the **Run query** action **** in response to the button **Click** event.
44

5-
<figure><img src="../.gitbook/assets/image (19).png" alt=""><figcaption></figcaption></figure>
5+
<figure><img src="../.gitbook/assets/image (8) (1).png" alt=""><figcaption></figcaption></figure>
66

77
Set event handlers wisely to provide a reactive and responsive user experience (UX). For example, triggering a **get-all** query after **insert-new-data** query finishes enables table automatically refresh.
88

@@ -32,7 +32,7 @@ Running a query can result in success or failure, so queries have two events: **
3232

3333
There are a number of event handler actions available in Openblocks for handling different scenarios. Set them in the **Action** dropdown list in an event handler.
3434

35-
![](<../.gitbook/assets/image (1) (1).png>)
35+
![](<../.gitbook/assets/image (9) (1).png>)
3636

3737
{% hint style="info" %}
3838
See [advanced](event-handlers.md#advanced) on this page to know advanced settings.
@@ -48,7 +48,7 @@ Trigger the selected query.
4848

4949
To control a component, select a component in the **Component** dropdown list and call one of its methods in the **Method** dropdown list.
5050

51-
![](<../.gitbook/assets/image (17).png>)
51+
![](<../.gitbook/assets/image (29).png>)
5252

5353
### Set temporary state
5454

‎docs/build-apps/module.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ When building an app, you want to reuse components and queries across different
44

55
<figure><img src="../.gitbook/assets/module-1.png" alt=""><figcaption><p>Build a <a href="module.md#demo-a-statistics-module">statistics module</a></p></figcaption></figure>
66

7-
<figure><img src="../.gitbook/assets/module-2.png" alt=""><figcaption><p>Reuse this module anywhere</p></figcaption></figure>
7+
<figure><img src="../.gitbook/assets/module-2 (1).png" alt=""><figcaption><p>Reuse this module anywhere</p></figcaption></figure>
88

99
## Module basics
1010

@@ -67,7 +67,7 @@ Module inputs are parameters passed to the module from external apps. The suppor
6767

6868
This section guides you through the steps to build a statistics module and reuse it in an app. &#x20;
6969

70-
<figure><img src="../.gitbook/assets/module-2.png" alt=""><figcaption></figcaption></figure>
70+
<figure><img src="../.gitbook/assets/module-2 (1).png" alt=""><figcaption></figcaption></figure>
7171

7272
1. Create module inputs:
7373

@@ -86,7 +86,7 @@ This section guides you through the steps to build a statistics module and reuse
8686
<figure><img src="../.gitbook/assets/module-17.png" alt=""><figcaption></figcaption></figure>
8787
5. Reuse the module multiple times by passing different input values.&#x20;
8888

89-
<figure><img src="../.gitbook/assets/module-2.png" alt=""><figcaption></figcaption></figure>
89+
<figure><img src="../.gitbook/assets/module-2 (1).png" alt=""><figcaption></figcaption></figure>
9090

9191
#### Input Test
9292

‎docs/build-apps/use-third-party-libraries.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ https://unpkg.com/cowsay@1.5.0/build/cowsay.umd.js
7070

7171
Navigate to the left sidebar, click <img src="../.gitbook/assets/image (1).png" alt="" data-size="line"> > **Other** > **Scripts and style** > **Add a library**. Then paste the **cowsay** link here.
7272

73-
<figure><img src="../.gitbook/assets/Add a library (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
73+
<figure><img src="../.gitbook/assets/Add a library (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
7474

7575
Now you can write code in **JS query** to test its usage with `cowsay.say`:
7676

77-
<figure><img src="../.gitbook/assets/write code in JS query (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
77+
<figure><img src="../.gitbook/assets/write code in JS query (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
7878

7979
or in component **Properties**:
8080

81-
<figure><img src="../.gitbook/assets/or in Properties (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
81+
<figure><img src="../.gitbook/assets/or in Properties (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
8282

8383
And since you have set up cowsay just for **Openblocks's new application 1,** you can not use cowsay in another app.
8484

85-
<figure><img src="../.gitbook/assets/in another app (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
85+
<figure><img src="../.gitbook/assets/in another app (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
8686

8787
### Import on Workspace-level
8888

‎docs/build-apps/write-javascript/javascript-query.md

+3-11
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function getCurrentDate() {
198198
}
199199
```
200200
201-
## Customized scripting
201+
## Add preloaded scripts
202202
203203
Openblocks supports importing third-party JS libraries and adding predefined JS code, such as adding global methods or variables for reuse either at **app-level** or **workspace-level**. You can find the app-level settings in ⚙️ > **Other** > **Scripts and style**.
204204
@@ -208,20 +208,12 @@ For workspace-level, go to ⚙️ **Settings** > **Advanced**.
208208
209209
<figure><img src="../../.gitbook/assets/js-query-5.png" alt=""><figcaption></figcaption></figure>
210210
211-
### Import JS library
212-
213-
Openblocks supports setting up preloaded JS libraries. For detailed information, see [use-third-party-libraries.md](../use-third-party-libraries.md "mention").
214-
215-
<figure><img src="../../.gitbook/assets/js-query-6.png" alt=""><figcaption></figcaption></figure>
216-
217-
### Define global methods and variables
218-
219-
In **JavaScript** tab, you can add preloaded JavaScript code to define global methods and variables and then reuse them in your app.
211+
In **JavaScript** tab, you can add preloaded JavaScript code to define global methods and variables and then reuse them in your app. For importing libraries, see [use-third-party-libraries.md](../use-third-party-libraries.md "mention").
220212
221213
<figure><img src="../../.gitbook/assets/js-query-7.png" alt=""><figcaption></figcaption></figure>
222214
223215
<figure><img src="../../.gitbook/assets/js-query-8.png" alt=""><figcaption></figcaption></figure>
224216
225-
## Restrictions
217+
## &#x20;Restrictions
226218
227219
For security reasons, several global variables and functions of **window** are disabled in Openblocks. Please report to our [GitHub](https://github.com/openblocks-dev/openblocks) or [Discord](https://discord.com/invite/z5W2YHXdtt) if you encounter any issues.

‎docs/data-sources/connect-to-databases-1/google-sheets.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Navigate back to to [Google Sheets](https://docs.google.com/spreadsheets), and f
3737
1. Open the JSON file of the key.
3838
2. Copy the value of `client_email`, which is an identity used for access management of your sheet.
3939

40-
<figure><img src="../../.gitbook/assets/Google-sheets-key-client-email (1).jpeg" alt=""><figcaption></figcaption></figure>
40+
<figure><img src="../../.gitbook/assets/Google-sheets-key-client-email.jpeg" alt=""><figcaption></figcaption></figure>
4141
3. Click **Share** at the top right and paste the copied `client_email` value to add a member with access.
4242

4343
<figure><img src="../../.gitbook/assets/Google-sheets-share.jpg" alt=""><figcaption></figcaption></figure>

‎docs/data-sources/data-source-basics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Follow the steps below:
1515
1. Click **Data Sources** on Openblocks homepage.
1616
2. Click **New data source** on the upper right. This permission is restricted to workspace admins and developers.
1717

18-
<figure><img src="../.gitbook/assets/image (12) (1).png" alt=""><figcaption></figcaption></figure>
18+
<figure><img src="../.gitbook/assets/image (31) (1).png" alt=""><figcaption></figcaption></figure>
1919
3. Select the database or API type you need to connect.&#x20;
2020

2121
<figure><img src="../.gitbook/assets/data source basics-2.png" alt=""><figcaption></figcaption></figure>
22-
4. Fill out data source connection fields. See docs in [Connect to databases](broken-reference) and [Connect to APIs](connect-to-databases-1/) for detailed tutorials.
22+
4. Fill out data source connection fields. See docs in [Connect to databases](broken-reference) and [Connect to APIs](connect-to-databases/) for detailed tutorials.
2323
5. Click **Test connection** to check whether you can make a successful connection to data source based on current settings.
2424
6. Click **Save**.
2525

‎docs/queries/query-basics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Queries support you to read data from or write data to your data sources. You ca
66

77
You can connect to a data source that was already in your data source library or create a new one. For detailed information, see [data-source-basics.md](../data-sources/data-source-basics.md "mention").
88

9-
<figure><img src="../.gitbook/assets/image (31) (1).png" alt=""><figcaption></figcaption></figure>
9+
<figure><img src="../.gitbook/assets/image (12) (1).png" alt=""><figcaption></figcaption></figure>
1010

1111
## Create a query
1212

0 commit comments

Comments
 (0)