override _fnFilterCreateSearch... where exactly do I put the new version?

override _fnFilterCreateSearch... where exactly do I put the new version?

merlynmerlyn Posts: 3Questions: 0Answers: 0
edited October 2011 in DataTables 1.8
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?

Replies

  • merlynmerlyn Posts: 3Questions: 0Answers: 0
    OK, client is willing to pay hard cash to get this solved quickly. Please contact merlyn@stonehenge.com for details.
  • allanallan Posts: 61,824Questions: 1Answers: 10,131 Site admin
    edited October 2011
    Hi merlyn,

    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
  • merlynmerlyn Posts: 3Questions: 0Answers: 0
    Well, is there a way I can monkeypatch that function after I load it, just to ensure that I'm protected against future updates of the source? I'd really really rather not edit the source file. What's the full path to where that function ends up?
  • allanallan Posts: 61,824Questions: 1Answers: 10,131 Site admin
    Because of the way DataTables has been written there currently isn't a way of overriding the internal private functions. I do want to do a major change in architecture at some point which will allow that kind of thing, but I'm afraid at the moment the only way of modifying the built in functions is to edit the core file (media/js/jquery.dataTables.js in the download package).

    Regards,
    Allan
This discussion has been closed.