简体   繁体   English

搜索不在datatables中工作 - Jquery

[英]Search not working in datatables - Jquery

My datatable is filled with inputs from the server side but unfortunately my search box is not filtering my data. 我的数据表充满了服务器端的输入,但不幸的是我的搜索框没有过滤我的数据。 When i search on page 1, it doesn't filter. 当我在第1页上搜索时,它不会过滤。 When i move to page 2 of the pagination and start searching in the box, it automatically moves me to page 1 again. 当我移动到分页的第2页并开始在框中搜索时,它会自动将我移至第1页。

There's no error showing in the console as well to give me a hint. 在控制台中也没有显示错误,并给我一个提示。 What could be causing this please? 有什么可能导致这个问题?

PS: I am using yajra package datatables. PS:我正在使用yajra包数据表。

JS Scripts JS脚本

$(document).ready(function() {
    oTable = $('#users-table').DataTable({
        "processing": true,
        "serverSide": true,
        "bProcessing":false,
        "bSort":false,
        "ajax": "{{ route('datatable.getcategories') }}",
        "columns": [
            {data: 'check', name: 'check'},      
            {data: 'name', name: 'name'},
           // {data: 'description', name: 'description'},
            {data: 'count', name: 'count'},
            {data: 'action', name: 'action'}        
        ],
        language: { search: "" },
    });

    $('.dataTables_filter input[type="search"]')
        .attr('placeholder','  Search...');
});

Apparently you have chosen server side processing by setting serverSide to true . 显然,您通过将serverSide设置为true来选择服务器端处理。 With that every time you type something into the search field, an ajax request is sent to the server with the value of the search field and it is the task of the server to respond with the filtered dataset. 随着每一个你输入的东西在搜索字段中时,一个Ajax请求被发送到服务器与搜索字段的值,它是服务器与过滤数据集响应的任务。 However, based on your comments, I assume that you had the default client side processing working earlier and your server has not been prepared to do the processing. 但是,根据您的评论,我假设您的默认客户端处理工作较早,而您的服务器尚未准备好进行处理。 To have the filtering processed on the client side, you can simply comment out the "serverSide": true, line, like so: 要在客户端处理过滤,您只需注释掉"serverSide": true, line,如下所示:

var oTable = $('#users-table').DataTable({
    'processing': true,
    // 'serverSide': true,// false is the default
    'bProcessing':false,
    'bSort':false,
    'ajax': "{{ route('datatable.getcategories') }}",
    'columns': [
        {data: 'check', name: 'check'},      
        {data: 'name', name: 'name'},
       // {data: 'description', name: 'description'},
        {data: 'count', name: 'count'},
        {data: 'action', name: 'action'}        
    ],
    language: { search: '' },
});

Please note that you should declare the variable oTable with var in order to not create it as a global variable ( var oTable = …; ). 请注意,您应该使用var声明变量oTable ,以便不将其创建为全局变量( var oTable = …; )。

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

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