Skip to main content

getData()

Description

Gets a promise with an array of objects with data for the Grid
info

The getData() method is a part of the RestDataProvider service intended for working with a server

Usage

getData(): Promise<[]>

Response

The getData() method sends a request to the server by the GET method and returns a promise with data for the Grid (columns IDs with values for each row). For an example of returned objects, see data.

Example

<script>
import { RestDataProvider } from "@wx/table-data-provider";
import { Grid } from "../src/";

const columns = [
{
id: "name",
header: "Title",
flexgrow: 1,
sort: true,
editor: "text",
},
{
id: "year",
header: "Year",
width: 100,
sort: true,
editor: "text",
},
{
id: "votes",
header: "Votes",
width: 100,
sort: true,
editor: "text",
},
];

let data = [];
const provider = new RestDataProvider("https://some-backend-url", (obj) => {
obj.year = obj.year * 1;
obj.votes = obj.votes * 1;
});

provider.getData().then((v) => (data = v));

let api;

const init = (api) => {
api.setNext(provider);
};

</script>

<Grid {data} {columns} bind:api {init} />

Related articles: