When server side processing starts scrolling datatable
When server side processing starts scrolling datatable
when I load data to my datatable (e.g. 400 rows from 1700 data in database) and I scroll down the table, when will my server side code be triggered?
I found out, that if my server side code is very quick, it will be triggered after every 16 rows when I scroll down, although there are 400 rows inside the table. When I do a sleep of 1000 msec in my server side code, it will be triggered later.
Is there an option I can configure the triggering, let's say 20 rows before the end of the last line is reached?
Answers
.
Can you link to a page showing the issue please? It should be that Scroller will do exactly as you say - wait until the scrolling is near the limit of the data it has before making a request to the server for more data.
Allan
Hello Allen,
Thanks for your answer.
Unfortunately the scroller doesn't do exactly what I expected and as you described. I probably didn't express myself correctly and I'll try again.
I have a DataTable that displays 48 rows. The DataTable has a length of 400. My server side code connects to a database and determines a total of 1700 valid rows. Of these 1700 lines it returns 400 lines to the DataTable - so far everything is ok.
What I noticed is different behavior when calling the server side code through the DataTable.
Version 1:
If the server side code determines the data very quickly and delivers it to the DataTable, the DataTable calls the server side code as soon as I scroll with the mouse to the lines directly below / the next page (lines 48 - 96). The server side code is called again with start=16 and length=400, even though I have already loaded 400 lines and there are still around 350 lines left for a display.
Variant 2:
If I incorporate a sleep of 1000 msec into the server side code, the server side code is not called when scrolling to the lines below (48-96) / next page. Only when I get to line 282 will my server side code with start=32 (why 32?) and length=400 be triggered again.
I also increased the sleep to 2000 msec. However, the same behavior is seen here as with 1000 msec (variant 2). Then I continuously turned the sleep down. It turns out that the behavior changes with a total running time of the server side function of approx. 700 - 800 msec:
- Total runtime under 700 to 800 msec: permanent call to the server side code upon click
- Total running time more than 700 - 800 msec: The server side code is only called when the available lines are displayed - as desired.
My questions:
Is there a mechanism within the DataTable that evaluates and uses the speed of the server side code?
Can I use parameters/options to tell the DataTable when it can call the server side code?
Here are some code fragments:
javascript:
table = $('#myID').DataTable({
dom: 'tSr',
processing: true,
ordering: true,
order: [[1, "asc"]],
scrollCollapse: false,
paging: true,
serverSide: true,
ajax: {
url: "/Controller/Method",
data: {
data1: "myData",
data2: "myData",
data9: "myData",
},
columnDefs: [{ data: "data1", "orderable": true},
{ data: "data2", "orderable": true},
{ data: "data3", "orderable": true}]
});
later in code:
let table = $('#myID').DataTable();
table.page.len(400);
server side code C#:
public object Method(JQueryDataTableParamModel DT-Params)
{
/* get data from database */
/* build json reply */
System.Threading.Thread.Sleep(1000);
return Newtonsoft.Json.JsonConvert.SerializeObject(jsonReply);
}
Can you give me a link to a page showing the issue please? I've just had a look at this example and it appears to be doing what I would expect.
Allan
Hi Allen,
here are two videos:
This shows the behavior as I expect:
https://www.youtube.com/shorts/DRcDnxAP7OE
This shows the permanent call to the server side function:
https://youtube.com/shorts/cCi07vxjmLU
Sorry for the poor quality. Video captureing is not possible.