jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
585 stars 228 forks source link

filter/search not working for me #329

Closed epipheus closed 5 years ago

epipheus commented 5 years ago

filtering and searching doesn't seem to work for me while using this gem. I assume the filtration happens client side after getting all the raw records. Am I wrong in this assumption? Do I need to pass params and have get_raw_records filter/search? Presently I am using the below javascript which at the end uses a searchbox on the table -- it sends the query on keyup but always just gets all the records.

jQuery(document).ready(function() {
  var table = $('#organizations-datatable');
  var token = $('meta[name=csrf-token]').attr('content');
  var settings = {
    "sDom": "<t><'row'<p i>>",
    "processing": true,
    "serverSide": true,
    "ajax": {
      "url": "/organizations/datatable.json",  //$('#organizations-datatable').data('source'),
      "type": 'POST',
      "beforeSend": function (xhr) {
          xhr.setRequestHeader('X-CSRF-Token', token)
        }
    },
    "pagingType": "full_numbers",
    "destroy": true,
    "scrollCollapse": true,
    "processing": true,
    "serverSide": true,
    "oLanguage": {
        "sLengthMenu": "_MENU_ ",
        "sInfo": "Showing <b>_START_ to _END_</b> of _TOTAL_ entries"
    },
    "columns": [
      {
        "data":   "name",
        "width":  "15%",
        "searchable": true
      },
      {
        "data": "desc",
        "width":  "45%",
        "searchable": true
      },
      {
        "data": "industry",
        "width":  "15%",
        "searchable": true
      },
      {
        "data": "tags",
        "width":  "25%",
        "searchable": true
      }
    ],
    "iDisplayLength": 25
  }

    table.DataTable(settings);

    $('#search-table').on( 'keyup', function () {
    table.DataTable(settings).search( this.value );
} );
});
epipheus commented 5 years ago

i added searchable: true even though it;s yhte default and I can see in the logs that search and order is set to true. What am I missing here? I don't see this in the documentation. I've poured over it.

epipheus commented 5 years ago

closing. the issue was that was trying to search on tags (acts_as_taggable) It started working when I made the tags searchable:false