$.fn.datatable.ext.search.push not call
$.fn.datatable.ext.search.push not call
maboteo
Posts: 2Questions: 1Answers: 0
i try... i try.. i try but i don't get the way..
I use server-side method to get the data, can is it the problem?
this is the initialization..
$(document).ready(function() {
var dt = $('#datatable').DataTable( {
"applyFilter":true,
"bJQueryUI": true,
"bFilter": true,
"bSort": true,
"language": {
"lengthMenu": "Visualizza _MENU_ records per pagina",
"zeroRecords": "Nessun record trovato!",
"info": "Pagina _PAGE_ di _PAGES_",
"infoEmpty": "No records available",
"infoFiltered": "(filtrati da _MAX_ records totali)"
},
"lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"displayLength": 100,
"processing": true,
"serverSide": true,
"stateSave": true,
"ajax": "controller_spese.php",
"columns": [
{ "data": "scDateScad" },
{ "data": "Fornitore" },
{ "data": "scName" },
{ "data": "Tipologia" },
{ "data": "scEuro" },
{ "data": "scState"}
],
"scrollY": "600px",
"scrollCollapse": true,
"paging": false,
"order": [[0, 'desc']]
} );
//this is the event listener
$('#min, #max').change( function() {
console.log("dentro");
dt.draw();
} );
// and in the extern of "$(document).ready(function() {" i put the example..
$.fn.datatable.ext.search.push(
function( settings, data, dataIndex ) {
var min = $('#min').val();
var max = $('#max').val();
var age = parseFloat( data[0] ) || 0; // use data for the age column
console.log("dentro ext...");
if ( ( isNaN( min ) && isNaN( max ) ) ||
( isNaN( min ) && age <= max ) ||
( min <= age && isNaN( max ) ) ||
( min <= age && age <= max ) )
{
return true;
}
return false;
}
);
where i take the cow by the balls???
This discussion has been closed.
Answers
You are mixing a client-side filter, with server-side processing - with server-side processing all of the filtering is done at the server. So using the client-side filter will never work!
If you want to perform filtering, it has to be done at the server and you'd need to adjust your server-side script accordingly if you want to continue using server-side processing.
Allan
can you give me a link for an example of custom filter with server-side script.
i think i need to use a "post" method into the ajax call.
something who can be so:
var dt = $('#datatable').DataTable( {
}
} );
I'm afraid I don't have one. You would need to modify whatever is in
controller_single_act.php
to perform the filter - presumably using an SQL WHERE condition, but it depends upon your script. Theajax.data
parameter can be used to send the filtering information to the server - you should use it as a function so it is executed on each request.Allan
Hi to everybody!
@maboteo, did you resolve your problem? If yes, could you explain me your approach?
I've created an ajax call that returns me an object with the same "shape" of the response of the server-side script that is in every server-side example, but I cannot understand how to re-draw the table with that infos.
Someone has an idea?
Thanks for the help!
@cla - I think we would need more information that you have provided to be able to offer any help. A link to the page showing the issue for example.
Allan
Thanks Allan!
I want to filter my table, but with the
serverside
on, I cannot use the $.fn.datatable.ext.search.push function.I though that, if I can obtain the same structure of the server response with filtered rows (with an ajax call that return me that filtered table object), it will be possible to call
or something like this, in order to draw the "new" table.
draw()
accepts only one parameter and that tells DataTables how the draw should be performed. There is no option to draw only certain rows.Allan
Maybe I've understood something...
I pass with
ajax.data
an indicator of which table I want to recall (full_table, date_filtered_table, etc...).For example:
structure is a variable initialized to 'full_table'.
After that, in that php file with a case I can recall the different tables:
The file selected with 'full_table' is the "default" server-side script, instead of the other one that give me the table filtered.
now, if I set the variable structure with the appropriate value when I want add a filter to the table (or eliminate it), can I recall the different tables (maybe with a table.draw() )?
yes you can see that I want to resolve all with
draw
...That looks fine. If you are using server-side processing then
ajax.data
will always be sent to the server.Allan
Thank you!
I've tried
with
but I have an error:
Where is my fault?
Hi,
This is not linear method. but it works.
Without a link to a test case I can't say for sure. My guess is that this relates to the top FAQ.
Allan
Grazie @ambose!
I've also found this discussion:
https://www.datatables.net/forums/discussion/30286/ajax-reload-is-not-sending-updated-params
and this worked for me!
When I'll have more time I'll test your solution!
now I've another issue... if I limit the row returned by the server to the pagination value (for example 10 row), the 1st page view is correct, but obviously I've no other pages to show.
If I don't limit it, all the rows are showed.
Practical example: paginator set to 10; I need to display 17 rows filtered. In the first case, only the first 10 are showed but the paginator indicator is not shown, in the second case the paginator correctly have 2 pages but all the 17 rows are shown in the first and in the second page.
Is it possible to correct this? Thank you!