We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Custom data adapter and virtual scrolling

Because our RESTful API doesn't use the result/count response style but a flat array and `X-Total-Count` header, I figured I had to write a custom data adapter.

class ApiAdaptor extends UrlAdaptor {
  processQuery(dm: DataManager, query: Query, hierarchyFilters?: Object[]) {
    let original = super.processQuery.apply(this, arguments);
    let data = JSON.parse(original.data);

    return {
      data: JSON.stringify({ value: data }),
      url: `${original.url}?offset=${data.skip}&limit=${data.take}`,
      pvtData: original.pvtData,
      type: 'GET',
      contentType: 'application/json; charset=utf-8'
    };
  }

  processResponse(data, ds, query, xhr, request, changes) {
    return {
      result: super.processResponse.apply(this, arguments),
      count: xhr.getResponseHeader('X-Total-Count')
    };
  };
}

The grid component has [enableVirtualization]=true and I've loaded VirtualScrollService as a provider.

It does seem to work fine but virtual scrolling doesn't work properly with this adapter. If I scroll down, right before the point where subsequent data will be loaded and then scroll down a row further, the new data is loaded and rendered on the grid from the top down. Of course, the new data should only be rendered in the open space at the bottom. In other words: when the new data is loaded, the grid is effectively scrolled all the way to the point where the new data was loaded.

This results in a jumping grid experience.

Is there something I'm doing wrong?

2 Replies

SA Sandor April 5, 2019 01:09 PM UTC

Well, it turned out that I wasn't loading the ej2 style properly. I loaded it from the component instead of globally. This probably caused the grid to calculate the grid size incorrectly, thus causing the jumpy scrolling.



PS Pavithra Subramaniyam Syncfusion Team April 8, 2019 04:52 AM UTC

Hi Sandor, 
 
Thanks for contacting Syncfusion support. 
 
We are happy to hear that your issue has been resolved. 
 
Please contact us if you need any further assistance. 
 
Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon