Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServerDataSource: Setting filters sends new network request when doEmit=true #105

Closed
SZOKOZ opened this issue Oct 10, 2022 · 2 comments
Closed
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@SZOKOZ
Copy link

SZOKOZ commented Oct 10, 2022

const source = new ServerDataSource(this.http,
      {
        endPoint: `${this.apiUrl}/${uri}`,
        dataKey: '',
        pagerPageKey: 'pageNumber',
        pagerLimitKey: 'pageSize',
        filterFieldKey: 'filterBy#field#',
        sortFieldKey: 'sortBy',
        sortDirKey: 'orderBy',
      });
    source.setFilter([
      {
        field: 'type',
        search: 'engine',
      },
    ]); // Results in a http get request
    source.setPaging(1, 1); // Results in a http get request
    
    // Actual intentional attempt to retrieve data.
    source.getElements().then(response => console.log(response));

Setting the filter calls the parent set filter which emits a filter event calling emitOnChanged leading to a http call with the currently set filter. Setting paging has the same issue.

In the docs the doEmit flag is used to determine whether or not the table is refreshed and theoretically helpful for detecting changes but what it actually does is grossly different.

@uap-universe
Copy link
Collaborator

I am not sure if I understand the issue correctly.

Changing the pagination or the filter must result in a http request, because the items of the current page might change.

If the observation is, that an additional http request with the old and outdated filter or pagination is sent, then this is obviously a bug.

Can you please clarify?

@uap-universe uap-universe added the investigation-needed An issue needs to be analyzed label Oct 25, 2022
@uap-universe uap-universe self-assigned this Oct 27, 2022
@uap-universe uap-universe added enhancement New feature or request and removed investigation-needed An issue needs to be analyzed labels Oct 27, 2022
@uap-universe uap-universe added this to the v2.7.0 milestone Oct 27, 2022
@uap-universe
Copy link
Collaborator

uap-universe commented Oct 27, 2022

It looks like the ServerDataSource needs to remember the last query parameters s.t. subsequent calls to

  • getAll()
  • getElements()
  • getFilteredAndSorted()

can return the last result without issuing a new request. On the other hand, there needs to be a way to invalidate this "cache", because otherwise you would not get fresh data from the server.

I would override the refresh() method for this. This way you get new data from the server

  • every time the query changes (changing the page or the filter)
  • on explicit calls of refresh()

In my opinion the ServerDataSource is a bit broken anyway, because it inherits from LocalDataSource but has completely different semantics. For example I don't know what prepend or empty should mean in the context of a ServerDataSource....

The enhancement is described in ticket #106.

To solve this issue here it only needs a bit more documentation.

@uap-universe uap-universe added documentation Improvements or additions to documentation and removed enhancement New feature or request labels Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants