Datatable Proxy with Pager

Hello,

to manipulate the URL of a datatable before loading, we have built our own proxy. Specifically, it is about a default sort order that we want to control via the configuration of the datatable.

Now when I use the Datatable’s pager, the data is loaded twice each time via the proxy.

We use the following URL to load the data:

"datatableProxy->/alphaflow-contract/contractservice/contracts?i18n=true&continue=true&count=" + $$(oConfig.sTableId).getVisibleCount();

The code of the proxy looks like this:

webix.proxy.datatableProxy = {
            $proxy: true,
            load: function (view, params) {
                let url = this.source;

                if (params) {
                    for (const [key, value] of Object.entries(params)) {
                        if (key !== "filter" && key !== "sort") {
                            url += "&" + key + "=" + value;
                        } else if (key === "filter") {
                            for (const [filterKey, filterValue] of Object.entries(value)) {
                                url += "&filter[" + filterKey + "]=" + (typeof filterValue === 'object' ? JSON.stringify(filterValue) : filterValue);
                            }
                        } else if (key === "sort" && Array.isArray(value)) {
                            value.forEach(sortValue => {
                                url += "&sort[" + sortValue.id + "]=" + sortValue.dir;
                            });
                        } else if (key === "sort" && typeof value === 'object') {
                            url += "&sort[" + value.id + "]=" + value.dir;
                        }
                    }
                }

                if (url.indexOf("sort") == -1 && view.config.defaultSort) {
                    $$(view.config.id).markSorting();
                    view.config.defaultSort.forEach(sortValue => {
                        url += "&sort[" + sortValue.id + "]=" + sortValue.dir;
                        $$(view.config.id).markSorting(sortValue.id, sortValue.dir, true);
                    });
                }

                return webix.ajax(url);
            }
        };

Does anyone have any idea why the proxy is being called twice? Is there possibly a better solution for the default sorting?

Thanks and best regards
Gorden

Good day @gokap001!

Could you send the full configuration of your table, please?

As a reference, you can use this snippet: Code Snippet
It uses your code from the example and the simple regular table/pager config. When navigating through the pages, you can see the logic inside works only once (webix.message shows only one message as in the console).

Please clarify, does your data is loaded twice only at the very beginning, or with each request?
In some cases, on the init, it’s possible two requests are sent, and this is basically normal

Hello Natasha,

thanks for the reply.

I’ve added our Datatable Configuration to the Snippet: Code Snippet

The behavior is the same. I hope you can do something with it.

If you need more information, feel free to contact me.

Many thanks and greetings
Gorden

multiple requests at startup are related with low datafetch amount.
in your case page size is 25 but datafetch is 10.
that is why there are multiple requests at first page.
but double requests at next pages somehow are related with pager’s animation.
try to increase datafetch and remove animation from pager.

Good day @gokap001!

To work correctly, it’s necessary the size of the table be the same as the property datafetch.

Double load on the next pages is a bug, we will fix it as soon as possible. As a workaround, you can delete the property animation: Code Snippet