# loadData

## Description

Loads the data from a local table, staging database or 3rd party connector.

## Input / Parameter

| Name    | Description                                                                        | Input Type | Default | Options | Required |
| ------- | ---------------------------------------------------------------------------------- | ---------- | ------- | ------- | -------- |
| dataset | The name of the local table to load data from.                                     | Text       | -       | -       | Yes      |
| fields  | Specifies which fields to retrieve from the local table.                           | List       | -       | -       | No       |
| join    | Details about any tables to be joined with the primary dataset for data retrieval. | Array/List | -       | -       | No       |
| filter  | The filters for the fields and values to retrieve.                                 | List       | -       | -       | Yes      |
| sort    | Specifies the field and direction for sorting the returned data.                   | List       | -       | -       | No       |
| limit   | The number of records to be returned from the local table.                         | Number     | -       | -       | No       |
| page    | The page number for pagination purposes.                                           | Number     | -       | -       | No       |
| extra   | Extra parameters stored and passed to callback.                                    | Any        | -       | -       | No       |

## Output

| Description                        | Output Type |
| ---------------------------------- | ----------- |
| Returns the formatted information. | Object      |

### Object

| Key     | Description                                                             | Output Type |
| ------- | ----------------------------------------------------------------------- | ----------- |
| success | Boolean value to denote whether the function was executed successfully. | Text        |
| message | The message to print.                                                   | Text        |
| data    | Any additional message or data to print.                                | Text        |

## Callback

### callback

The function to be executed if the records are loaded successfully.

### errorCallback

The function to be executed if the records are not loaded successfully.

## Example

In this example, we will load the data from the Local Table and display it in a flatlist component.

```js
Note: This example will only work after the user has created the data using `Dataset.insert` function.
```

### Steps

1. Make sure a `Local Table` component is created and filled on the services panel in the service page.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-b87cd62feb0cb7e6500969aefd8b62d33a145c59%2FloadData-step-1.png?alt=media)
2. Drag a button component to a page in the mobile designer.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-a60cc4bc547cf0e380593d4f9928386a23eb7e5c%2FloadData-step-2.png?alt=media)
3. Drag a `flatlist` component to a page in the mobile designer, and drag a `label` component into the `flatlist` component.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-100438a96526e4423d19cbc0e3af396a25254e6a%2FloadData-step-3.png?alt=media)
4. Fill the `flatlist` component property in the page and fill the `label` component property in the `flatlist` component, make sure the `label` component `field` value matches the key of the data that is being stored in the local table.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-5ca570b13c8763d8e3fbb12cd2153c34add6f00d%2FloadData-step-4.png?alt=media)
5. Select the event `press` and drag the `Dataset.loadData` function to the event flow. Fill in the parameters of the function.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-cf5e9eefa4804418f414c1a3b38fc111119176b0%2FloadData-step-5.png?alt=media)

### Result

1. The data should be loaded from the local table and displayed in the flalist component.
