1

要求 :

我正在寻找将大型dataset服务器加载到jQuery DataTables.

我不想一次加载整个数据,而是想逐块加载表。当用户单击分页索引时,进行 ajax 调用获取几百行。

例子 :

因此,在一个网格中,每页只有 10 条记录可见,并且分页将高达50 index( 10(records per page)*50(pages) = 500(records))。单击第 50 个索引时,我们要获取另一个500 records并添加相同的datatable索引,然后索引将高达100

我有一个1500记录数据集,但有一次我只能获取500记录。

我正在探索各种问题,SOdatatable forum到目前为止仍然没有找到解决方案。

数据表论坛: 尝试做客户端延迟加载

4

1 回答 1

0

I'll give a conceptual answer since i don't know anything about your server. Basically on the client you have a page variable which initializes to 0. On your server you have a chunk variable which is set to 10. Each time you need to load data, you increment page and send an ajax request with the page as a parameter.

Your server will then query the database for rows page * chunk through (page * chunk)+chunk-1). This requires that you select all rows, give each row an index, and then retrieve the proper chunk. Notice the -1 for [inclusive,exclusive] chunks.

Example:

page = 0; chunk start index = page * chunk = 0 chunk end index = page * chunk + chunk - 1 = 9

Retrieve rows 0-9 from database.

page = 1; chunk start index = page * chunk = 10 chunk end index = page * chunk + chunk - 1 = 19

Retrieve rows 10-19 from database.

page = 2; chunk start index = page * chunk = 20 chunk end index = page * chunk + chunk - 1 = 29

Retrieve rows 20-29 from database.

You can tweek the chunk variable to how ever many records you want per call.

于 2016-04-15T01:28:07.027 回答