Filtering - an exact match

Filtering - an exact match

big-dealbig-deal Posts: 38Questions: 0Answers: 0
edited February 2011 in General
Hey.

When filtering specific columns using a select - I don't want it to filter smartly.
If I filter by code for example, and I look for '1', I don't want it to find all the '1' as well as all of the '11'.
I wrote oSettings.aoPreSearchCols[ iColumn ].sSearch = '1'; oTable.fnDraw(); , and got '11' as well.
What can I do?

Replies

  • 28.vivek.s28.vivek.s Posts: 69Questions: 0Answers: 0
    edited February 2011
    disable smart filtering and enable regex filtering by writing true as last argument in fnFilter();

    Thanks,
    Vivek
  • big-dealbig-deal Posts: 38Questions: 0Answers: 0
    I don't use fnFilter() but:
    oSettings.aoPreSearchCols[ iCol ].sSearch = '1';
    Hence, I do:
    oSettings.aoPreSearchCols[ iCol ].bRegex = false;
    oSettings.aoPreSearchCols[ iCol ].bSmart= false;

    I also tryed:
    oSettings.aoPreSearchCols[ iCol ].bRegex = true;
    oSettings.aoPreSearchCols[ iCol ].bSmart= false;


    Both didn't work out.
    Any ideas?
  • 28.vivek.s28.vivek.s Posts: 69Questions: 0Answers: 0
    disable both smart filtering and regx and use your own regular expression before passing the filter text ....try this..i have done this and got the exact result for which you are looking..

    [code]
    oSettings.aoPreSearchCols[ iCol ].sSearch = "^\\s*"+'1'+"\\s*$";
    oSettings.aoPreSearchCols[ iCol ].bRegex = false;
    oSettings.aoPreSearchCols[ iCol ].bSmart= false;
    [/code]

    let me know it works for you are not...
  • big-dealbig-deal Posts: 38Questions: 0Answers: 0
    Sorry - i forgot to update.
    Worked like a charm - thanks.
  • choggerchogger Posts: 15Questions: 4Answers: 0
    Hello all, i have the same issue but i'm not shure were thislines of code belong to?
  • alanomalyalanomaly Posts: 4Questions: 0Answers: 0
    edited November 2011
    For anyone using fnFilter, to get an exact match you want something like this (assuming your table object is called oTable, like oTable = $('#some_id').dataTable(); ):

    [code]oTable.fnFilter("^"+some_string+"$", some_column_id, true);[/code]

    As for chogger's question, I couldn't find documentation on oSettings anywhere on this site, in the end I found it from stackoverflow... Looks like this:

    [code]
    // after creating the table and getting the table object...

    var oTable = $('#some_id').dataTable();

    // ...you can use it to get a settings object...

    var oSettings = oTable.fnSettings();

    // ...then you can do things with the settings object

    oSettings.aoPreSearchCols[ iCol ].sSearch = "^\\s*"+'1'+"\\s*$";
    oSettings.aoPreSearchCols[ iCol ].bRegex = false;
    oSettings.aoPreSearchCols[ iCol ].bSmart= false;
    [/code]
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > I couldn't find documentation on oSettings anywhere on this site

    I feel that this is possibly the biggest weakness in DataTables at the moment... :-(. oSettings was never intended (way back when I started DataTables) to be publicly documented (it is however fully documented in the code, if you look in the file), but it has become increasingly important that this and all the other internals of DataTables are fully documented. When 2.0 happens I plan to restructure DataTables to have it make a lot more sense from this point of view and full automatic documentation as well

    Until then, its a case of looking at the code if you want to mess around with the settings object.

    Having said that, generally you shouldn't need to - for example all that you've done above can be done with the publicly documented fnFilter API method.

    Regards,
    Allan
This discussion has been closed.