Phone number Search

Phone number Search

mild4umild4u Posts: 3Questions: 0Answers: 0
edited April 2011 in General
I am learning this wonderful new tool. I was able to integrate regular search feature on my table pretty easily. But I have now a speacial search i.e. the phone numbers in my table's "Phone" column is displayed in format (xxx) xxx xxxx

User will be searching directly by entering number e.g. 8882348483
The defualt search is able to identify individual 3 or 4 numbers.

Question:
How can I use DataTables' searching for my above need.

One idea I have is have a Separate input for filter by phone number. And upon key up I manually create my search string in format (xxx) i.e. if user inputs 123 I search for (123
This sounds little weired and I am sure there will be some easy way which I am unaware of due to my lack of knowledge about DataTables API.

Any inputs really appreciated. Thanks.

Replies

  • allanallan Posts: 63,230Questions: 1Answers: 10,416 Site admin
    There are a couple of options open to you for this I think:

    1. You could have a second hidden column with the unformatted number (which is put in place either by whatever is generating the table or fnRender) - which will allow the search to work regardless of input format.

    2. You could set the column sType to 'html' and have the unformatted number was part of an empty span tag's title attribute.

    3. Or you could do regex based filtering

    I think option 1 is probably the most attractive. Easiest to implement, most flexible, and would also allow you to use the iDataSort parameter to have the phone numbers sort numerically.

    Regards,
    Allan
  • mild4umild4u Posts: 3Questions: 0Answers: 0
    Thanks Allan for great suggestions.

    Option 1: Easiest one and I have implemented that in no time. Brilliant.

    Option 2: I didn't get it.

    Option 3: I would love to see sample on using regex based filtering. I looked through samples but didn't see something helpful.

    Right now I have to use this single column and so option 1 worked. But if I have more such formatted columns, I think duplicating columns for the sake of formatting will be a bad idea. If you have sometime and can provide me some samples or docs-link for option 3 it will be great.

    Thank you very much.
  • allanallan Posts: 63,230Questions: 1Answers: 10,416 Site admin
    Good to hear you got it working :-)

    What I'm working on at the moment is abstracting the data out from the presentation for DataTables 1.8. I think that will prove to be quite useful in that kind of situation. I plan to write a little tutorial about how to use the data manipulation options - I'll see if I can put something suitable in for this.

    Regards,
    Allan
This discussion has been closed.