#104054
pbgcosta
Participant

Defining de datasource like this … I always get two requests to the server .. if I call resultCallbackFunction with virtualDataSourceLength = the total length of the data
NOTE: backticks inside fetch are shown as . could not find a way of escaping them

        dataSource: new window.Smart.DataAdapter({

          virtualDataSourceCache: true,

          virtualDataSource: async function (resultCallbackFunction, details) {
            console.log(details);

            if (!tableReady) {
              return;
            }

            let sort = [];
            if (details.sorting.length > 0) {
              for (const s in details.sorting) {
                sort.push({
                  sortBy: s,
                  sortOrder: details.sorting[s].sortOrder
                });
              }
            }

            let filter = [];
            if (details.filtering.length > 0) {
              for (const f in details.filtering) {
                filter.push({
                  filterBy: f,
                  filterType: details.filtering[f].filters[0].type,
                  filterCondition: details.filtering[f].filters[0].condition,
                  filterValue: details.filtering[f].filters[0].value
                });
              }
            }

            const res = await fetch(encodeURI(<code>/table_data?first=${details.first}&last=${details.last}&sorting=${JSON.stringify(sort)}&filter=${JSON.stringify(filter)}</code>));
            const data = await res.json();
            resultCallbackFunction({
              dataSource: data.payload,
              virtualDataSourceLength: data.count
            });
          }

  • This reply was modified 1 year, 6 months ago by pbgcosta.
  • This reply was modified 1 year, 6 months ago by pbgcosta.
  • This reply was modified 1 year, 6 months ago by pbgcosta.
  • This reply was modified 1 year, 6 months ago by pbgcosta.
  • This reply was modified 1 year, 6 months ago by pbgcosta.
  • This reply was modified 1 year, 6 months ago by pbgcosta.
  • This reply was modified 1 year, 6 months ago by pbgcosta.
  • This reply was modified 1 year, 6 months ago by pbgcosta.