# Data Table Custom Query

{% hint style="info" %}
**Block Information**

Available in: Page Flow

Toolbox Category: Widget - Data Table

Block Type: [Regular](https://docs.zingy.ai/app-editor/block-anatomy#regular-block)
{% endhint %}

The **`Data Table Custom Query`** block allows you to use a custom [Database Query](https://docs.zingy.ai/app-editor/data/database-queries) for the [Data Table](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/data-table) widget.&#x20;

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FCYwmSsw7GeFSMhNJsxVR%2Fimage.png?alt=media&#x26;token=e1a5ba8b-79bd-4210-a239-cc15e0a2cb55" alt="" width="281"><figcaption><p>Data Table Custom Query block</p></figcaption></figure></div>

Normally the [Data Table](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/data-table) widget reads the [Database Table](https://docs.zingy.ai/app-editor/data/database-tables) without any match criteria or sorting rule. This block allows you to use a custom [Database Query](https://docs.zingy.ai/app-editor/data/database-queries) with matching criteria and/or sorting rules.

The block consists of the following (from top to bottom):

* *Data Table*: [Selectable Input](https://docs.zingy.ai/app-editor/block-anatomy#selectable-input) to choose the [Data Table](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/data-table) widget from your page.
* *Query Name*: a [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts a [*text*](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value representing the name of the [Database Query](https://docs.zingy.ai/app-editor/data/database-queries) to use.&#x20;
* *Input Params*: a [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts a [*list*](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value containing the matching criteria values for the various inputs used by the selected [Database Query](https://docs.zingy.ai/app-editor/data/database-queries) .
* *Per Page*: a [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts a [*numeric*](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value that specifies the number of records to load and display per page.

{% hint style="danger" %}
NOTE:

* To enable the functionality of this block, ensure that the [Custom Query setting](https://docs.zingy.ai/page-editor/built-in-elements/data-table#custom-query) of the [Data Table](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/data-table) widget is activated.
* The *Query Name* [value parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) needs to point to a valid [Database Query](https://docs.zingy.ai/app-editor/data/database-queries) defined in the associated [Database Table](https://docs.zingy.ai/app-editor/data/database-tables).
* The [Data Table Refresh](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-table-refresh) block needs to follow this block for the [Data Table](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/data-table) widget to load and display records.
  {% endhint %}

***

## Usage Example

The image below shows an example of the Data Table Custom Query block where the [Database Query](https://docs.zingy.ai/app-editor/data/database-queries) named *Q1* is used. A list containing two items is used as the matching criteria (via *Input Params)*. The number of records per page is set to *10*.

As previously mentioned, it's important to place a [Data Table Refresh](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-table-refresh) block after this one to ensure that the [Data Table](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/data-table) widget loads and presents the records. This is demonstrated in the example as well.

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2Fkfk1gWTgEzopaSM9dey0%2Fimage.png?alt=media&#x26;token=4e411135-2a98-4227-8467-0176e528ede5" alt=""><figcaption><p>Example of Data Table Custom Query block</p></figcaption></figure></div>
