column filter number error

column filter number error

skygod35skygod35 Posts: 2Questions: 1Answers: 0

I am using this column filtering code
https://datatables.net/extensions/fixedheader/examples/options/columnFiltering.html

I'm having trouble searching for the same numbers in the table
eg : "1" - "11" - "111"
I search for the number "1" but I come across the numbers "11" "111"

how can i fix this?

Answers

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    You'd need to use an exact match regular expression. By default we match on any part of the string, but if you were to use ^1$ then it will do an exact match.

    Allan

  • skygod35skygod35 Posts: 2Questions: 1Answers: 0

    how can i use this in code

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited July 2022

    Start by reading about the different search modes in the search() docs. The same is true for column().search(). The example you linked to uses this:

                                api
                                    .column(colIdx)
                                    .search(
                                        this.value != ''
                                            ? regexr.replace('{search}', '(((' + this.value + ')))')
                                            : '',
                                        this.value != '',
                                        this.value == ''
                                    )
                                    .draw();
    

    You will want to prefix the search value with ^ and postfix with $. Change line 5 to look like this:

    this.value != ''
      ? '^' + regexr.replace('{search}', '(((' + this.value + ')))') + '$'               
    

    Kevin

Sign In or Register to comment.