Skip to main content

data-request

Description

Fires while scrolling or at the initialization stage if dynamic data loading is enabled

Usage

"data-request": CustomEvent;

Parameters

The callback of the action is the function with the following parameter:

  • CustomEvent - a Svelte custom event which you can bind to the event handler

Example

In the example below we use the dynamic property to enable dynamic data loading and specify the number of all rows in a dataset. The data-request action is triggered while scrolling and we add the event handler that receives the row.start and row.end values and loads data.

<script>
import { Grid } from "@wx/svelte-grid";
import { getData } from "./common/data";
const { allData, columns } = getData();

let rowsCount = 500;

let data = [];

function dataProvider(ev) {
const { requestData } = ev.detail;
const { row } = requestData;

if (row) data = allData.slice(row.start, row.end);
}
</script>

<Grid
data={allData}
{columns}
dynamic={{ rowsCount }}
on:data-request={dataProvider} />

Related articles: Dynamic data loading