dataTables启用服务器端搜索

dataTables启用服务器端搜索

本文介绍了如何使用jQuery dataTables启用服务器端搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Datatables进行服务器端处理以显示数据.我想限制大约10000行数据以使其更具可读性.

I am using Datatables with server side processing to display data. I have around 10000 rows of data which I would like to limit to make it more readable.

我只想在数据表中显示50行数据.

I would like to display only 50 rows of data in the datatable.

$('#dataTable3').dataTable({
        "sAjaxSource": "user_data.php",
        "sPaginationType":"full_numbers",
        "bProcessing": true,
        "bPaginate":true,
        "iDisplayLength": 20,
        "aoColumns": [
        { mData: 'sno' } ,
        { mData: 'dob' } ,
        { mData: 'fullname' },
        { mData: 'email'}]
    });

服务器端PHP脚本将行数限制为50,如下所示:

The server side PHP script limits the number of rows to 50 as shown :

SELECT * FROM users order by id desc limit 50

现在,问题是如果我要搜索特定用户,它是从数据表的50行中搜索.我也想在服务器端进行搜索.知道怎么做吗?

Now, the issue is if I want to search for a particular user, it is searching from the 50 rows of the Datatable. I would like to search on the server side as well. Any idea how to do it ?

推荐答案

在通过 DataTables 使用服务器端处理时,必须考虑一些规则.

在每个执行的load数据表上,它都会向服务器发送一些参数,并期望其他参数返回以标识数据数量过滤器申请.

There are some rules you have to consider when you are using server-side processing with DataTables.

On every load datatables executes, it sends some parameters to your server and it expects some others back to identify the data, quantity and filters to apply.

您需要阅读datatables发送的请求中的内容,并将其应用于您的过滤器和数据库上的数据提取.

You need to read those on the request sent by datatables and apply them on you filters and data fetching on you database.

您可以在此图片.

如@Bindrid所述,您可以在此处查看这些参数的详细定义. .

此处此处,您可以检查该怎么做
当然,还有示例 datatables文档.

As mentioned by @Bindrid, you can check the detailed definition of those parameters here.

There is a good tutorial here and here that you can check how to do that using PHP.
And, of course, there is also the example on the datatables documentation.

这篇关于如何使用jQuery dataTables启用服务器端搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 21:15