How do I modify Input search with regular expression to filter on first word of a column only?

How do I modify Input search with regular expression to filter on first word of a column only?

BPATBPAT Posts: 28Questions: 13Answers: 1

I have this in my code and it doesn't seem to work.
$('input[type = search]').on( 'keyup', function () {
dataTableExample.column(0).search("\ba"+ this.value, true, false, true).draw();
alert('hello');
});

So if I enter ma in the input field, it filters to AMA, management, magma, etc. What I would really want is it to filter to management and column values that start with MA and not contain MA.

I am sure I'm doing something stupid, so feel free to point it out to me. :)

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @BPAT ,

    If you use regular expressions (there'll be loads of links on Google), it'll be easy - something like "^MA",

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    Answer ✓

    You need to escape the backslash like this: `"\b". For example:
    http://live.datatables.net/sinaxapa/1/edit

    Took me a minute to realize that problem :smile:

    Kevin

This discussion has been closed.