Custom filtering - range search without jquery

Custom filtering - range search without jquery

zehgehzehgeh Posts: 7Questions: 2Answers: 0

Hi, I have datatables (1.12.1) without jquery and everything works except my custom filtering. Does the function exist without jquery? https://datatables.net/examples/plug-ins/range_filtering.html

I do not know how to address the function since $.fn. does not exist anymore.

Thanks for the help.

Best Christoph

$.fn.dataTable.ext.search.push(function (settings, data, dataIndex) {
...

Replies

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

    DataTable.ext.search is the object to use. $.fn.DataTable is basically the same as the global DataTable.

    Allan

  • zehgehzehgeh Posts: 7Questions: 2Answers: 0

    Thanks allan, but if I do that, I won't get anything back. No error or console output.

    import DataTable from 'datatables.net-bs5';
    
    DataTable.ext.search.push((settings, searchData) => {
        console.log(searchData, 'searchData')
        const creditor = document.querySelector('.filter input.autocomplete').value;
    
        if (creditor === '') {
            return true;
        }
    
        return creditor.indexOf(searchData[3]) !== -1;
    });
    
  • zehgehzehgeh Posts: 7Questions: 2Answers: 0

    I have created an example: http://live.datatables.net/capabofi/26/edit

    If jquery is loaded, the example also works. If I remove jquery, the filter no longer works.

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

    According to the Manual Datatables requires jQuery:

    DataTables 1.10+ and its extensions require with jQuery 1.7 or newer.

    Possibly your import includes jQuery. Datatalbes itself won't initialize if you remove jquery.js from the test case you posted.

    I won't get anything back. No error or console output.

    Are you saying you don't see any rows, are they all filtered?

    Or do you mean that you aren't seeing the output of console.log(searchData, 'searchData')?

    Are you initializing the search plugin before or after initializing Datatables. Are you doing something to trigger the plugin to run like calling draw() to draw the table?

    Better than answering these questions is to provide a link to your page or a test case replicating the problem so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

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

    The current release of DataTables doesn't work with ESModules - are you using something to convert your import statement into a require? I think a minimal repo showing the issue might be the best option here to provide a test case.

    DataTables 1.13 which will drop next week, will include support for ESModules.

    Allan

Sign In or Register to comment.