0

I'm learning how to use ag-grid in react and I saw a problem:

when I'm getting data from a web api it cames very results, like 8600 results

Question:

I want to know if it is possible, for example, to get just 20 results per page instead get them all at once or it is possible just from an api prepared with this insight

some code:

//http request

onGridReady = params => {
  this.gridApi = params.api;
  this.gridColumnApi = params.columnApi;

  const httpRequest = new XMLHttpRequest();

  httpRequest.open( "GET", "https://raw.githubusercontent.com/ag-grid/ag-grid/master/packages/ag-grid-docs/src/olympicWinners.json" );
  httpRequest.send();
  httpRequest.onreadystatechange = () => {
    if (httpRequest.readyState === 4 && httpRequest.status === 200) {
      updateData(JSON.parse(httpRequest.responseText));
    }
  };
  
  const updateData = data => {
    this.setState({ rowData: data });
  };
};


//ag grid

render() {
  return (
      <div className="ag-theme-balham" style={{ height: '700px', width: '95%' }}>

        <AgGridReact
          columnDefs={this.state.columnDefs}
          defaultColDef={this.state.defaultColDef}
          defaultColGroupDef={this.state.defaultColGroupDef}
          columnTypes={this.state.columnTypes}
          rowData={this.state.rowData}
          onGridReady={this.onGridReady}
          pagination={true}          
          paginationPageSize={20}
        />
      </div>
  );
}
Community
  • 1
  • 1
Catarina
  • 359
  • 3
  • 16
  • In your case the data is not paginated but I think the grid has [pagination](https://www.ag-grid.com/javascript-grid-pagination/) – HMR Oct 18 '19 at 14:23
  • Check this: https://stackoverflow.com/questions/33635919/xmlhttprequest-chunked-response-only-read-last-response-in-progress – Oleg Oct 18 '19 at 14:23
  • @HMR yes, it has and i'm using, but I think when I use pagination it continues to get all all at once – Catarina Oct 18 '19 at 14:30
  • @HMR it is just possible if api has this pagination? (I'm new using api's) – Catarina Oct 18 '19 at 14:31
  • The examples seem to get all the data at once as well, there is no other way because it requests a json file, is your grid not creating pages? – HMR Oct 18 '19 at 14:33
  • @HMR my grid is okay with pages, my question it was just if it's possible to do it with every api or not, if you want to make a answer about what you said (that is no way because is just json file, etc...) to close this question.. ahah – Catarina Oct 18 '19 at 14:39
  • 1
    The answer is no because you are requesting a json file, not a json endpoint. If you are requesting an endpoint then you can (for example) add parameters such as page=.. and size=.. – HMR Oct 18 '19 at 14:43

1 Answers1

1

Answering my question according to the HMR comment:

The answer is no because you are requesting a json file, not a json endpoint.

If you are requesting an endpoint then you can (for example) add parameters such as page=.. and size=..

Community
  • 1
  • 1
Catarina
  • 359
  • 3
  • 16