override _fnFilterCreateSearch... where exactly do I put the new version?
override _fnFilterCreateSearch... where exactly do I put the new version?
merlyn
Posts: 3Questions: 0Answers: 0
I have a client that wants a case sensitive search, so I need to replace _fnFilterCreateSearch, but I'm unclear at exactly what point to do that.
I've tried something like:
[code]
$('.datatable').each(function() {
var $thistable = $(this);
var oTable = $thistable.dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"oSearch": { "sSearch": "", "bRegex": true, "bSmart": false },
});
oTable.oApi._fnFilterCreateSearch = function ( sSearch, bRegex, bSmart )
.... new function definition
};
};
[/code]
But that doesn't seem to ever be triggered. I'm lost in all the indirection, I guess. Can someone throw me a cluestick?
I've tried something like:
[code]
$('.datatable').each(function() {
var $thistable = $(this);
var oTable = $thistable.dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"oSearch": { "sSearch": "", "bRegex": true, "bSmart": false },
});
oTable.oApi._fnFilterCreateSearch = function ( sSearch, bRegex, bSmart )
.... new function definition
};
};
[/code]
But that doesn't seem to ever be triggered. I'm lost in all the indirection, I guess. Can someone throw me a cluestick?
This discussion has been closed.
Replies
Generally speaking I wouldn't recommend modifying the DataTables core file (simply so you can easily update it in future), but I think this is one of the occasions where a very simple edit will do what you are looking for. Specifically, you are quite correct in saying that _fnFilterCreateSearch is the function you need to change - to make it case sensitive you need to change the line (i.e. actually in the jquery.dataTables.js file, since its a private function that can't be overridden):
> return new RegExp( sRegExpString, "i" );
and
> return new RegExp( sSearch, "i" );
Simply remove the "i" parameter so you have:
> return new RegExp( sRegExpString );
and
> return new RegExp( sSearch );
And that will make the filtering DataTables does case sensitive. Then if you upgrade the core file in future, all you need to do is remember to make this change again :-). Ultimately what would be nice is to have this as a configuration option, and it is something I will consider for future releases if the feature is requested by a couple of others.
Regards,
Allan
Regards,
Allan