Strange issue with specific numbers search...

Strange issue with specific numbers search...

7stars7stars Posts: 9Questions: 0Answers: 0
edited November 2018 in Free community support

Hello,
a simple table with 5 columns

Checkbox | Number | Number | Filename | a href

eg. put in the columns numbers from 780 to 900

if you search for 789 and 890 the search fails and nothing happens.

So, there could be something wrong with the search logic (consecutive numbers? 123... 3456... 567... ? )
Please, could you test and fix it?

It happens on the bootstrap 4 version, downloaded from the wizard.

Here's my code now

var table = $('#mytable').DataTable( {
pageLength : 5,
lengthMenu: [[5, 10, 20, 25, 50, -1], [5, 10, 20, 25, 50, "Alles"]],
"language": {
"url": "assets/DataTables/German.json"
},
columnDefs: [
{ targets: [0, 4], "searchable": false},
{ targets: [0, 4], "orderable": false},
{ "type": "num", targets: [1, 2, 3] }
]
} )

Replies

  • 7stars7stars Posts: 9Questions: 0Answers: 0

    I also tried with html instead of num and does the same.

    It works for other numbers, it doesn't work for those kind of numbers only.
    Thank you

  • kthorngrenkthorngren Posts: 20,257Questions: 26Answers: 4,761
    edited November 2018

    if you search for 789 and 890 the search fails and nothing happens.

    Are you typing this into the default search box 789 and 890?

    It works for other numbers, it doesn't work for those kind of numbers only.

    Sorry its not clear what this means.

    So, there could be something wrong with the search logic (consecutive numbers? 123... 3456... 567... ? )
    Please, could you test and fix it?

    Can you put together a simple test case replicating the issue with the steps needed to show the issue?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • 7stars7stars Posts: 9Questions: 0Answers: 0

    I can confirm...
    I put inside even 234 and it fails.

  • kthorngrenkthorngren Posts: 20,257Questions: 26Answers: 4,761

    Sorry its still not clear what could be wrong. Searching for number sin Datatables works, you can try this example:
    https://datatables.net/examples/basic_init/zero_configuration.html

    It maybe that I don't understand your data structure. You mention consecutive numbers. Does this mean that you are putting consecutive numbers in one cell?

    Again please put together is simple example representing your data so we can help.

    Kevin

  • 7stars7stars Posts: 9Questions: 0Answers: 0
    edited November 2018

    Are you typing this into the default search box 789 and 890?
    I write 789 OR 890, one at a time...obviously
    I mean that it fails with numbers like that
    eg. if you write
    234
    345
    789
    890...
    probably there's something wrong when the numbers are consecutive, even if that's weird. What may be the cause?

    Here the fiddle which shows you a simple table where it just doesn't work
    https://jsfiddle.net/20tpf41k/5/

    So, if you put five elements per page, and search for 789, it just fails.

  • 7stars7stars Posts: 9Questions: 0Answers: 0

    well, I was able to let it run here https://jsfiddle.net/20tpf41k/5/ as you can see.

    Please, now search for 789 and you can see it failing...

    so, is there something into the html table declaration which does conflict or is datatables failing on its own about the search? But, why it happens just with those numbers and not with others? A mistery.

  • 7stars7stars Posts: 9Questions: 0Answers: 0
    edited November 2018

    Hello, i found the conflict with

    bootstrap.min.js from Bootstrap v4.1.3
    if you exclude it, indeed, then the datatables works as usual.and 789 (example) is not an issue anymore

    So, how to fix it, please?
    Thank you

  • 7stars7stars Posts: 9Questions: 0Answers: 0
    edited November 2018

    Even if

    Step 1. Choose a styling framework DataTables

    Step 2. Select packages DataTables

    so, all DataTables...no Bootstrap reference at all,
    it does conflict with the bootstrap.min.js and you can't search for those numbers because it does nothing, no errors, no filter, nothing on screen...so in this example you type 789 and it doesn't work

  • kthorngrenkthorngren Posts: 20,257Questions: 26Answers: 4,761
    edited November 2018

    Thanks for the example, it is very helpful to understand the issue. I don't think it has to do with using Bootstrap. What you are seeing is normal default behavior of Datatables search.

    Here is the data in your table:

    783,183,IT01234567890_783.xml   
    784,185,IT01234567890_784.xml   
    785,785,IT01234567890_785.xml   
    786,786,IT01234567890_786.xml   
    787,787,IT01234567890_787.xml   
    788,788,IT01234567890_788.xml   
    789,789,IT01234567890_789.xml
    

    When doing the default search of 789 Datatables will match all rows since 789 is in all the rows. It is found in IT01234567890_783.xml in all rows. The same behavior can bee seen in the regex search example:
    https://datatables.net/examples/api/regex.html

    Use the Global Search and leave the search default settings of Treat as regex unchecked and Use smart search checked. Enter 47 into the Global Search and there will be 4 rows with age 47 displayed and another row where $470,600 is also matched. Similar to what you are seeing in your table.

    If you just want the age 47 then you will need to use regex searching by checking the Treat as regex option and unchecking Use smart search. In the Global Search input type the regex expression\D47\D. You will see only the rows with age 47 appear.

    You could use a regex search to get just the last row when searching for 789, for example:

    table.search('\\D789\\D', true, false).draw();
    

    This can be seen in the updated example here:
    https://jsfiddle.net/20tpf41k/5/

    You may need to create a new search input for the Ordine n. and Fattura n. columns to use the regex while using the default search for the other columns.

    Kevin

  • 7stars7stars Posts: 9Questions: 0Answers: 0
    edited November 2018

    yes, you're right...indeed i forgot this and i was about to write here but you preceded me.
    But, while those strings/numbers are there, at the same time
    there is the option
    { targets: [0, 4], "searchable": false}

    or I didn't understand how it works or please explain why it doesn't exclude that column from the search.
    I know that there is IT01234567890 but at the same time i tried to exclude that column from the search, precisely because I don't need it.
    Instead, this means that it's included. Please, how to exclude a column from the search?

  • kthorngrenkthorngren Posts: 20,257Questions: 26Answers: 4,761

    The columns start counting at 0. You have 5 columns in your table. With targets: [0, 4] you are excluding the first column and the last. The IT01234567890 values are in the forth column but it is referenced as column(3). You will want targets: [0, 3, 4].

    Kevin

  • 7stars7stars Posts: 9Questions: 0Answers: 0

    sorry, i was wrong
    { targets: [0, 3, 4], "searchable": false}
    nevermind :lol:
    thanks

  • kthorngrenkthorngren Posts: 20,257Questions: 26Answers: 4,761

    No problem. Glad we worked it out :smile:

    Kevin

This discussion has been closed.