table.search.fixed is not a function. Why?

table.search.fixed is not a function. Why?

VladimirDremineVladimirDremine Posts: 2Questions: 1Answers: 0
edited April 1 in Free community support

I am using same scripts as in the example https://datatables.net/examples/plug-ins/range_filtering.html, but getting this error(also just copied example code to my own js file).

My js files:

<script type="text/javascript" src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/v/dt/dt-2.0.3/datatables.min.js"></script>

My code:

const table = new DataTable('#discovery-list', params)

table.search.fixed('range', function (searchStr, data, index) {
            var min = parseInt(resultForFiltering[0])
            var max = parseInt(resultForFiltering[1])
            var age = parseFloat(3) || 0; // use data for the age column

            if (
                (isNaN(min) && isNaN(max)) ||
                (isNaN(min) && age <= max) ||
                (min <= age && isNaN(max)) ||
                (min <= age && age <= max)
            ) {
                return true;
            }
          
            return false;
          });

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,401Questions: 26Answers: 4,787
    Answer ✓

    Not sure why you are getting the error. I copied your code snippet into this test case and no error:
    https://live.datatables.net/luyivofa/1/edit

    I'm not sure what you are doing with these 3 statements:

                var min = parseInt(resultForFiltering[0])
                var max = parseInt(resultForFiltering[1])
                var age = parseFloat(3) || 0; // use data for the age column
    

    So I replaced them with the ones in the example. I added the inputs and the event handlers and the test case works properly.

    Possibly you have something loading in the wrong order. Make sure you are loading datatables.js only once. We will need to see the issue to help debug. Please post a link to your page or a test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • VladimirDremineVladimirDremine Posts: 2Questions: 1Answers: 0

    My bad! Didn't really find an error, but copied all code to another page and it have worked. Thx)

Sign In or Register to comment.