Filter rendered column with server side processing

Filter rendered column with server side processing

sergio_nubeamesergio_nubeame Posts: 2Questions: 1Answers: 0

Hi,

I've tried to filter data that are rendered. To make it easy I've summarized the code:

var columnas = [
  {"data": 'maquina_id', name:'maquina_id', searchable: true },
];

var columnDefs = [{
  "targets": 4, //maquina
  "render": function(data, type, row) {
    return '<a href="'+baseUrl+'/maquinas/'+data+'">\
      Nº de serie: '+row['numero_serie']+' <br>\
      Marca: '+row['maquina_marca']+' <br>\
      Modelo: '+row['maquina_modelo']+'\
    </a>';
  }
}];

$('#lista').DataTable( {
  "processing": true,
  "serverSide": true,
  "search": {
    "caseInsensitive": true
  },
  "ajax": baseUrl+"/datatable",
  "columns": columnas,
  "columnDefs" : columnDefs,
  "searching": true
});

On server I have something like this:

[...]
$q = $a->datatable();
return Datatables::of( $q->get() )->setTransformer('App\Transformers\AlbaranTransformer')->make(true);
[...]

Well, If I search something, datatable does not filter by "numero_serie", "maquina_marca" or "maquina_modelo".
Wich is the appropiate way to do this?

Thank you

Answers

  • Dalex73Dalex73 Posts: 30Questions: 4Answers: 4

    Since you are using "serverSide": true, you need to do the search/filtering in your backend or database and return the results.

  • sergio_nubeamesergio_nubeame Posts: 2Questions: 1Answers: 0
    edited September 2017

    Hi Dalex,

    Yes you are right in part, but if I use serverSide with DataTable plugin, the plugin makes a query like:

    SELECT * FROM table WHERE (cond1 OR cond2 OR cond3);
    

    And when I add more "where", It looks like:

    SELECT * FROM table WHERE (cond1 OR cond2 OR cond3) AND (myCond1 OR myCond2 OR myCond3);
    

    This behaviour is not the right way

This discussion has been closed.