Filter by length of text

Filter by length of text

Bama5150Bama5150 Posts: 8Questions: 0Answers: 0
edited April 2013 in General
I have tried doing so with regular expressions. Is there a simple way to filter a column based on the number of characters in the cell?
Thanks for your help.
Jeremy

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Not internally in DataTables. Can you can do is simply call fnFilter only when the input is a certain length, so you'd use your own event handler. e.g.:

    [code]
    if ( $('#myInput').val().length > 3 ) {
    table.fnFilter( $('#myInput').val();
    }
    [/code]

    Allan
  • Bama5150Bama5150 Posts: 8Questions: 0Answers: 0
    thank you Allan. Didn't even cross my mind to do it that way.

    Really fantastic resource you've created here...
  • Bama5150Bama5150 Posts: 8Questions: 0Answers: 0
    Ok, after looking this over more closely, this actually wont work for me. I dont think i did a good job explaining what I am trying to accomplish.

    I have a single column of serial numbers.
    I have a drop down that calls an eventhandler.

    in the eventhandler I need it to filter the column.
    The first criteria is that every cell has to start with the letter P
    the second criteria is that the text in the cell has to be exactly 5 characters. if its 6 characters etc it gets filtered out.

    thanks
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    > I have a drop down that calls an event handler.

    I presume that it is a `select` list. What are the options in the list. You might need to use fnFilter with a regex filer, or perhaps ultimately custom filtering.

    Allan
  • Bama5150Bama5150 Posts: 8Questions: 0Answers: 0
    yes its a select list. The option simply states 'End of Life' which means any serial number starting with P and contains 4 numbers plus the P for a total of 5 characters.

    ya im using $.fn.dataTableExt.afnFiltering.push that does date range filtering...
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    You could use a filter call of:

    [code]
    table.fnFilter( '^P\d\d\d\d$', null, false );
    [/code]

    to do a regex filter which matches your description.

    Allan
This discussion has been closed.