Sort Datatable by server in the first request.

How to sort datatable by server in the first request but loading 10 rows and when rotating the mouse loads more rows.
I tried with this.sort(‘id’,‘desc’) but get this error " can’t access property “id”, t is undefined ".
I also tried with scheme:{
$sort:{
by:“id”,
dir:“desc”,
as:server
}
}
but don’t make the sort.

Hi @AlenaLisava

When using

scheme:{
  $sort:{
    by:"title",
    dir:"desc",
    as: "server"
  }
}

this I get this error message Client sorting can't be used with dynamic loading

thanks for the awesome information.

Hello, @ Tarcantos

Sorting is a client-side feature, i.e. it works only with the data that exists in the component. Dynamic loading requests a batch of data when the user scrolls down to the rows that were not loaded yet. Until then, the datatable simply reserves the space and position for them, but they cannot be sorted (as there’s no item ID to refer to). That is the reason for the error you’ve got.

Speaking about

scheme:{
  $sort:{
    by:"id",
    dir:"desc",
    as:server
  }
}

That is possible to use that version but combined with a pager, that would allow you to display a new chunk of sorted data. Please, check the snippet here: Code Snippet

But in general, in the case of dynamic loading, you can use server-side filtering and server-side sorting ( that means component will reload data on sorting and filtering )
Here is the snippet: Code Snippet

Hello, @mgraph2010

Sorry for the delay with the answer.

In general, the first request for the initial data portion comes without parameters at all. SetState triggers its (second) query by sorting;
As a solution, you could try to include sorting in the first request through a proxy.

thanks for the awesome information.