Skip to content

Commit

Permalink
chore: update JSDoc to use fetch in the data provider (#3098) (#3099)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaadin-bot authored Nov 24, 2021
1 parent 230206c commit 0f70965
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 50 deletions.
41 changes: 16 additions & 25 deletions packages/grid/src/vaadin-grid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,38 +253,29 @@ export interface GridEventMap<TItem> extends HTMLElementEventMap, GridCustomEven
* in the second argument of the data provider callback:__
*
* ```javascript
* grid.dataProvider = function(params, callback) {
* const url = 'https://api.example/data' +
* '?page=' + params.page + // the requested page index
* '&per_page=' + params.pageSize; // number of items on the page
* const xhr = new XMLHttpRequest();
* xhr.onload = function() {
* const response = JSON.parse(xhr.responseText);
* callback(
* response.employees, // requested page of items
* response.totalSize // total number of items
* );
* };
* xhr.open('GET', url, true);
* xhr.send();
* grid.dataProvider = ({page, pageSize}, callback) => {
* // page: the requested page index
* // pageSize: number of items on one page
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
*
* fetch(url)
* .then((res) => res.json())
* .then(({ employees, totalSize }) => {
* callback(employees, totalSize);
* });
* };
* ```
*
* __Alternatively, you can use the `size` property to set the total number of items:__
*
* ```javascript
* grid.size = 200; // The total number of items
* grid.dataProvider = function(params, callback) {
* const url = 'https://api.example/data' +
* '?page=' + params.page + // the requested page index
* '&per_page=' + params.pageSize; // number of items on the page
* const xhr = new XMLHttpRequest();
* xhr.onload = function() {
* const response = JSON.parse(xhr.responseText);
* callback(response.employees);
* };
* xhr.open('GET', url, true);
* xhr.send();
* grid.dataProvider = ({page, pageSize}, callback) => {
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
*
* fetch(url)
* .then((res) => res.json())
* .then((resJson) => callback(resJson.employees));
* };
* ```
*
Expand Down
41 changes: 16 additions & 25 deletions packages/grid/src/vaadin-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,38 +139,29 @@ import { StylingMixin } from './vaadin-grid-styling-mixin.js';
* in the second argument of the data provider callback:__
*
* ```javascript
* grid.dataProvider = function(params, callback) {
* const url = 'https://api.example/data' +
* '?page=' + params.page + // the requested page index
* '&per_page=' + params.pageSize; // number of items on the page
* const xhr = new XMLHttpRequest();
* xhr.onload = function() {
* const response = JSON.parse(xhr.responseText);
* callback(
* response.employees, // requested page of items
* response.totalSize // total number of items
* );
* };
* xhr.open('GET', url, true);
* xhr.send();
* grid.dataProvider = ({page, pageSize}, callback) => {
* // page: the requested page index
* // pageSize: number of items on one page
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
*
* fetch(url)
* .then((res) => res.json())
* .then(({ employees, totalSize }) => {
* callback(employees, totalSize);
* });
* };
* ```
*
* __Alternatively, you can use the `size` property to set the total number of items:__
*
* ```javascript
* grid.size = 200; // The total number of items
* grid.dataProvider = function(params, callback) {
* const url = 'https://api.example/data' +
* '?page=' + params.page + // the requested page index
* '&per_page=' + params.pageSize; // number of items on the page
* const xhr = new XMLHttpRequest();
* xhr.onload = function() {
* const response = JSON.parse(xhr.responseText);
* callback(response.employees);
* };
* xhr.open('GET', url, true);
* xhr.send();
* grid.dataProvider = ({page, pageSize}, callback) => {
* const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
*
* fetch(url)
* .then((res) => res.json())
* .then((resJson) => callback(resJson.employees));
* };
* ```
*
Expand Down

0 comments on commit 0f70965

Please sign in to comment.