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

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((response) => {
data = response;
});

export default function App() {
const api = useRef(null);

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

return (
<Grid data={data} columns={columns} api={api} init={init} />
);
}

Related articles: