Filter: must type 3 chars

Filter: must type 3 chars

romsokromsok Posts: 38Questions: 0Answers: 0
edited December 2009 in General
Hi,

Currently the filter only starts working when I type 3 characters or more.

Is there a way to configure it?

Replies

  • allanallan Posts: 61,835Questions: 1Answers: 10,134 Site admin
    Actually the filter starts as soon as you start typing, rather than at 3 characters. Have a look at the example on the home page ( http://datatables.net ) and type a 'z' into the filter. You'll see it match against 'Mozilla' only, with 9 records showing.

    Therefore, that suggests that what you are searching for matches some of the text in the table somewhere, for the first two characters.

    Allan
  • romsokromsok Posts: 38Questions: 0Answers: 0
    It doesn't work on my end for some reason.
    I have a table with 12 rows: one for each month.
    The leftmost column contains the names of all 12 months.
    The rest of the columns contain only statistical numeric info.
    When I type the letter "F" in the search box, nothing happens - the July row for example is still displayed.
  • allanallan Posts: 61,835Questions: 1Answers: 10,134 Site admin
    In that case you've likely either got a configuration error, or an 'F' somewhere in the row. Can you post a link to an example showing the problem?

    Allan
  • romsokromsok Posts: 38Questions: 0Answers: 0
    Unfortunately, I am not at liberty to post this particular content. I will try to replicate it at home and post some dummy content from there.
  • romsokromsok Posts: 38Questions: 0Answers: 0
    Is it possible that the filter is picking up things like
    [b]class="leftSide"[/b] or [b]href[/b] from the markup?
  • allanallan Posts: 61,835Questions: 1Answers: 10,134 Site admin
    Not just possible - it is what happen. :-)

    You can over rule this default behaviour, as shown here:
    http://datatables.net/examples/advanced_init/html_sort.html

    Allan
  • romsokromsok Posts: 38Questions: 0Answers: 0
    Could you please confirm I understood the usage in the example correctly?

    If I have a table with 7 columns, the leftmost one is a string, and the others are numeric, I would initialize like this?
    [code]
    $(document).ready(function() {
    $('#table1').dataTable(

    {
    "bPaginate": false,
    "bInfo": false,
    "bSortClasses": true,
    "bJQueryUI": true,
    "aoColumns": [
    null,
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" }
    ]

    }

    );
    } );
    [/code]

    And if I have the next table the same, except the leftmost column is a name of month, it would be initialize like this?
    [code]
    $(document).ready(function() {
    $('#table2').dataTable(

    {
    "bPaginate": false,
    "bInfo": false,
    "bSortClasses": true,
    "bJQueryUI": true,
    "aoColumns": [
    { "sType": "date" },
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" },
    { "sType": "numeric" }
    ]

    }

    );
    } );
    [/code]
  • allanallan Posts: 61,835Questions: 1Answers: 10,134 Site admin
    Hi romsok,

    I think you have the basic syntax and idea right - but the usage is probably slightly off. The reason I say this is that DataTables will try to automatically detect date and numeric types. If it can't parse either of then then it falls back to HTML (with a special string type of "html" being provided, to strip HTML out and then sort by string). So you wouldn't need to explicitly say 'date' or 'numeric', and if you did - then it wouldn't work, since it can't be parsed :-)

    Do your numeric columns have HTML in them? Is that causing the problem? If so then you would need to use the HTML numeric sorting plug-in: http://datatables.net/plug-ins/sorting#numbers_html and give an sType of 'num-html'. There are also multiple date sorting plug-ins on that page which might help with your date sorting if you are having issues with that as well.

    Regards,
    Allan
  • romsokromsok Posts: 38Questions: 0Answers: 0
    Actually,

    I changed that particular code.
    I just strip off html.

    The only problem I still have is that if the table cell has "%" following the number, the sorting SOMETIMES gets messed up - percentages of "0.00%" come out as the largest instead of smallest, and percentages greater than 100 come out smallest.
  • allanallan Posts: 61,835Questions: 1Answers: 10,134 Site admin
    Hi romsok,

    I'm sure you realise, but just for anyone who finds this thread, the % issue is dealt with by my post here: http://datatables.net/forums/comments.php?DiscussionID=1022&page=1#Item_3

    Regards,
    Allan
This discussion has been closed.