简体   繁体   English

为什么服务器端分页不适用于我的jquery datatables表?

[英]Why doesn't server side pagination works for my jquery datatables table?

I'm trying to make server side pagination work but it just doesn't work. 我正在尝试使服务器端分页工作,但它只是不起作用。 I have been looking all over for a solution to my problem but everything I have found is pretty much the same I have, which does not work. 我一直在寻找解决我的问题的方法,但我发现的一切都和我一样,但是没有用。

I'm probably missing something obvious here, I haven't used datatables that good and I find its instructions and examples a bit too confusing. 我可能在这里遗漏了一些明显的东西,我没有使用好的数据表,我觉得它的指令和例子有点太混乱了。

Here's my Javascript code - it's being printed from inside a PHP file as inline Javascript code, so I had to replace PHP parts for brevity: 这是我的Javascript代码 - 它是从PHP文件内部打印为内联Javascript代码,因此我必须更换PHP部分以简化:

var display_start = 1;
var display_length = 10;

$( '#andrux' ).dataTable({
    'sPaginationType': 'full_numbers',
    'processing': true,
    'serverSide': true,
    'bSort': false,
    'ajax': '/bp-subgroups.php?group=3&iDisplayStart=' + display_start + '&iDisplayLength=' + display_length
});

According to the samples I've seen, I shouldn't even append the iDisplayStart or iDisplayLength variables to my request, but that's the only way I don't get the complete load of records into my table. 根据我见过的样本,我甚至不应该将iDisplayStart或iDisplayLength变量附加到我的请求中,但这是我没有将完整的记录加载到我的表中的唯一方法。

I know what happens in this scenario, I always send 1 and 10 as display start and display length in my request, I guess the question should be, how do I keep those updated depending on the page I'm at? 我知道在这种情况下会发生什么,我总是在我的请求中发送1和10作为显示开始和显示长度,我想问题应该是,如何根据我所在的页面保持更新? Shouldn't they be automatically updated with each request? 它们不应该随每个请求自动更新吗?

Here's the output I'm sending from my PHP code: 这是我从PHP代码发送的输出:

$output = array(
    "sEcho" => intval( $_GET['sEcho'] ),
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iTotal,
    "aaData" => array()
);

Of course aaData is being loaded with my rows, I only include the above for brevity, plus, I can see the data just fine, I just can't make it paginate. 当然aaData正在加载我的行,我只包括上面的简洁,加上,我可以看到数据很好,我只是不能让它分页。

Anyone with experience that can see what I'm doing wrong? 任何有经验的人都可以看到我做错了什么?

This is already driving me nuts, but I don't want to use another plugin for this, I don't like giving up! 这已经让我疯了,但我不想为此使用另一个插件,我不喜欢放弃!

Thanks everyone. 感谢大家。

Well, since no one gave this a shot I just had to exhaust all my resources and find a solution myself. 好吧,因为没有人给这个镜头我只需要耗尽我所有的资源并自己找到解决方案。

The answer was here: http://www.datatables.net/examples/data_sources/server_side.html 答案在这里: http//www.datatables.net/examples/data_sources/server_side.html

Inside the "Server-side script" tab, at the very bottom, they include the SSP class. 在“服务器端脚本”选项卡的最底部,它们包含SSP类。 Since I'm using WordPress here, I wrongly assumed I wouldn't need that class, because my queries are via $wpdb or other WP core functions, plus, I was reading all the documentation online and didn't even think of looking into that class - why would I, if I was following the rest of the instructions that were supposed to work. 由于我在这里使用WordPress,我错误地认为我不需要那个类,因为我的查询是通过$ wpdb或其他WP核心函数,而且,我正在阅读所有在线文档,甚至没有想到调查那个班级 - 如果我按照其他应该工作的指示,我为什么要这样做。

Long story short, I did some modifications to the SSP class to suit my needs, then used pretty much the same setup the example pages have, and finally got my datatables paginating correctly. 简而言之,我对SSP类进行了一些修改以满足我的需求,然后使用与示例页面几乎相同的设置,最后使我的数据表正确分页。

Just as reference, I was trying to return an array like the following to datatables: 就像参考一样,我试图将以下数组返回给datatables:

array(
    "sEcho" => intval( $_GET['sEcho'] ),
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iTotal,
    "aaData" => $my_data
);

When it turned out I need to return the array like this: 事实证明我需要像这样返回数组:

array(
    "draw"            => intval( $request['draw'] ),
    "recordsTotal"    => intval( $recordsTotal ),
    "recordsFiltered" => intval( $recordsFiltered ),
    "data"            => $my_data
);

Probably it's just me, but datatables although a nice working plugin, really needs more work on the documentation. 可能它只是我,但数据表虽然是一个很好的工作插件,但真的需要更多的文档工作。 I found some parameters were found one way in one place and another way elsewhere - just like the example above. 我发现一些参数在一个地方找到了一种方式,另一种在其他地方找到 - 就像上面的例子一样。

在我的情况下,我没有传递“draw”的值,请尝试传递此值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM