admin管理员组

文章数量:1429513

I'm using IgnitedDatatables (CodeIgniter library) for DataTables. The table gets generated without problems but if I search/filter it can only filter one column at a time. If I set "bServerSide" to false it works but then I lose the server-side functionality.

In the examples, this one is working: .html

while this isn't (server-side): .html

Is this not possible to achieve when running server-side?

This is my JSON response (shortened and with replaced data):

{"sEcho":0,"iTotalRecords":45438,"iTotalDisplayRecords":45438,"aaData":[["abc","12345","[email protected]","","","2010-01-27 22:31:10","Edit<\/a> Delete<\/a>"],["abc2"," test123","[email protected]","","","2008-06-15 22:09:33","Edit<\/a> Delete<\/a>"]],"sColumns":"fname,lname,email,phone,cellphone,created,edit"}

JavaScript code:

$("#members").dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    'sAjaxSource': '<?php echo base_url();?>members/listener',
    "fnServerData": function ( sSource, aoData, fnCallback ) {
        $.ajax( {
            "dataType": 'json',
            "type": 'POST',
            "url": sSource,
            "data": aoData,
            "success": fnCallback
        } );
    },
    "bLengthChange": false,
    "aaSorting": [[ 0, "asc" ]],
    "iDisplayLength": 15,
    "sPaginationType": "full_numbers",
    "bAutoWidth": false,
    "aoColumnDefs": [ 
        { "sName": "fname", "aTargets": [ 0 ] },
        { "sName": "lname", "aTargets": [ 1 ] },
        { "sName": "email", "aTargets": [ 2 ] },
        { "sName": "phone", "sWidth": "80px", "aTargets": [ 3 ] },
        { "sName": "cellphone", "sWidth": "100px", "aTargets": [ 4 ] },
        { "sName": "created", "sWidth": "120px", "aTargets": [ 5 ] },
        { "bSortable": false, "sName": "edit", "sWidth": "115px",   "aTargets": [ 6 ] }
    ]
});

Thank you!

I'm using IgnitedDatatables (CodeIgniter library) for DataTables. The table gets generated without problems but if I search/filter it can only filter one column at a time. If I set "bServerSide" to false it works but then I lose the server-side functionality.

In the examples, this one is working: http://datatables/release-datatables/examples/ajax/custom_data_property.html

while this isn't (server-side): http://datatables/release-datatables/examples/data_sources/server_side.html

Is this not possible to achieve when running server-side?

This is my JSON response (shortened and with replaced data):

{"sEcho":0,"iTotalRecords":45438,"iTotalDisplayRecords":45438,"aaData":[["abc","12345","[email protected]","","","2010-01-27 22:31:10","Edit<\/a> Delete<\/a>"],["abc2"," test123","[email protected]","","","2008-06-15 22:09:33","Edit<\/a> Delete<\/a>"]],"sColumns":"fname,lname,email,phone,cellphone,created,edit"}

JavaScript code:

$("#members").dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    'sAjaxSource': '<?php echo base_url();?>members/listener',
    "fnServerData": function ( sSource, aoData, fnCallback ) {
        $.ajax( {
            "dataType": 'json',
            "type": 'POST',
            "url": sSource,
            "data": aoData,
            "success": fnCallback
        } );
    },
    "bLengthChange": false,
    "aaSorting": [[ 0, "asc" ]],
    "iDisplayLength": 15,
    "sPaginationType": "full_numbers",
    "bAutoWidth": false,
    "aoColumnDefs": [ 
        { "sName": "fname", "aTargets": [ 0 ] },
        { "sName": "lname", "aTargets": [ 1 ] },
        { "sName": "email", "aTargets": [ 2 ] },
        { "sName": "phone", "sWidth": "80px", "aTargets": [ 3 ] },
        { "sName": "cellphone", "sWidth": "100px", "aTargets": [ 4 ] },
        { "sName": "created", "sWidth": "120px", "aTargets": [ 5 ] },
        { "bSortable": false, "sName": "edit", "sWidth": "115px",   "aTargets": [ 6 ] }
    ]
});

Thank you!

Share Improve this question edited Feb 10, 2016 at 10:41 Alessio Cantarella 5,2113 gold badges29 silver badges36 bronze badges asked Nov 14, 2011 at 10:52 RichardRichard 4,0875 gold badges30 silver badges34 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1

Well, the problem if you filter server side is that you are filtering through an SQL query and this is what is written on the example you posted;

  • Filtering
  • NOTE this does not match the built-in DataTables filtering which does it
  • word by word on any field. It's possible to do here, but concerned about efficiency
  • on very large tables, and MySQL's regex functionality is very limited

Basically you could do what you want to do (a regular expression match an all columns) but it's going to kill the performance server side.

What i usually do is provide a filter for each column, i need to filter.

本文标签: javascriptDataTables search all columns when serversideStack Overflow