Exact match search with serverside mode?
Exact match search with serverside mode?
Webface
Posts: 9Questions: 2Answers: 0
Dear community,
Is this possible exact match search with serverside mode?
I mean that i search ex. "124", i want to see only row which contain 124, not 1247, 1249, 12498, etc.
I try to put double quote in the search field, but it doesn't work...
My Javascript is:
` <script type="text/javascript" language="javascript" class="init">
function format ( d ) {
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tr>'+
'<td>Lakcím:</td>'+
'<td>'+d.tagok_irszam+' '+d.tagok_varos+', '+d.tagok_utca+'</td>'+
'</tr>'+
'<tr>'+
'<td>Szolgáltatásra jogosult:</td>'+
'<td>'+d.tagok_szolgaltatasra_jogosult+'</td>'+
'</tr>'+
'<tr>'+
'<td>Azonosítva?:</td>'+
'<td>'+d.tagok_is_azonositva+'</td>'+
'</tr>'+
'<tr>'+
'<td>Születési dátum:</td>'+
'<td>'+d.tagok_szuletesidatum+'</td>'+
'</tr>'+
'<tr>'+
'<td>Telefonszám:</td>'+
'<td>'+d.tagok_telefonszam+'</td>'+
'</tr>'+
'<tr>'+
'<td>TAJ szám:</td>'+
'<td>'+d.tagok_tajszam+'</td>'+
'</tr>'+
'<tr>'+
'<td>E-mail:</td>'+
'<td>'+d.tagok_email+'</td>'+
'</tr>'+
'<tr>'+
'<td>Tagdíj fizetés módja:</td>'+
'<td>'+d.tagok_tagdijbefizetes_modja+'</td>'+
'</tr>'+
'</table>';
}
$(document).ready(function() {
var dt = $('#example').DataTable( {
"search": [
{
"bRegex": true,
"bSmart": false,
}
],
"processing": true,
"serverSide": true,
"ajax": "server_side/scripts/ids-objects.php",
"columns": [
{
"class": "details-control",
"orderable": false,
"data": null,
"defaultContent": ""
},
{ "data": "tagok_nev" },
{ "data": "tagok_tagkod" },
{ "data": "tagok_ezevben_fizetett_osszes_tagdij" },
{ "data": "tagok_hatralek" }
],
"order": [[1, 'asc']]
} );
//BEGIN COLUMN SEARCH
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Keresés '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable();
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
//END OF COLUMN SEARCH
} );
// Array to track the ids of the details displayed rows
var detailRows = [];
$('#example tbody').on( 'click', 'tr td.details-control', function () {
var tr = $(this).closest('tr');
var row = dt.row( tr );
var idx = $.inArray( tr.attr('id'), detailRows );
if ( row.child.isShown() ) {
tr.removeClass( 'details' );
row.child.hide();
// Remove from the 'open' array
detailRows.splice( idx, 1 );
}
else {
tr.addClass( 'details' );
row.child( format( row.data() ) ).show();
// Add to the 'open' array
if ( idx === -1 ) {
detailRows.push( tr.attr('id') );
}
}
} );
// On each draw, loop over the `detailRows` array and show any child rows
dt.on( 'draw', function () {
$.each( detailRows, function ( i, id ) {
$('#'+id+' td.details-control').trigger( 'click' );
} );
} );
} );
</script>`
Any help appreciate!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @Webface ,
Yep, you'll need to do a regex
search()
on line 84 - so changeto be
Cheers,
Colin
Hi Colin,
Thanks, but unfortunatelly it's doesn'work...
With this change cant find anything...
Hi @Webface ,
That's definitely the syntax you need. Take a look at this example here - this is doing the same full search as I gave above. If you type 'London' into that third column, it only shows when fully matched.
Can you compare that with yours please, and if still no joy, it would be worth creating a similar example showing it not working.
Cheers,
Colin
Dear Collin,
Thank you for your help and kindness!
I check the syntax, and it seems that fine, but the script doesnt work for me...
Please take a look, and do a search in age, example: https://uat.tvep.hu/datatable/
My scrpts is:
HTML+Javascript:
ids-objects.php:
Big thanks!!!!!
Sorry, I missed the fact that you've got
serverSide
enabled - our server-side scripts don't support regex. The rationale is that you would only enable server-side if you've got 1000s or records - and a regular expression on that would be brutal. If your expected dataset is going to be small, you could ditch serverSide and do the processing on the client.Cheers,
Colin
Dear Colin,
Thanks for your quick reply!
Unfortunatelly we have a large database with more than 17 000 records...
So, i think we have to compromise...:)
Thanks again,
Best regards,
Laci