DataTables Editor and plugin fnFilterOnReturn

DataTables Editor and plugin fnFilterOnReturn

bccsergiobccsergio Posts: 2Questions: 1Answers: 0

I downloaded DataTables Editor today - Trial Mode - to try to integrate in my application. If I succeed I'll by a license.
Firsto problem I got is that Editor does not work with the plugin "fnFilterOnReturn" ( https://datatables.net/plug-ins/api/fnFilterOnReturn ). I got this error:
Uncaught TypeError: $datatable.DataTable(...).fnFilterOnReturn is not a function

If I start DataTable like this:
var table = $datatable.dataTable({
fnFilterOnReturn works BUT Editor does not.

If I start DataTable like this:
var table = $datatable.DataTable({
Editor works BUT fnFilterOnReturn does not.

As I use server side processing, it's really annoying to perform a serach on every KeyPress... this plugin to search only on Enter Key is a must have...

Is there a workaround to have both Editor and fnFilterOnReturn working on a DataTable simultaneously?

Best regards,
Sérgio Ávila

This question has an accepted answers - jump to answer

Answers

  • bccsergiobccsergio Posts: 2Questions: 1Answers: 0

    Update:

    tried calling from using:

    "fnInitComplete": function(oSettings, json) {
        table.fnFilterOnReturn();
    });
    

    without success.. got this error:
    table.fnFilterOnReturn is not a function

    just remembering that I do have //cdn.datatables.net/plug-ins/1.10.19/api/fnFilterOnReturn.js loaded, witch works fine without Editor, and my datatable is now initializing with this:
    table = $datatable.DataTable({

    I thought that this call on fnInitComplete should work, but that wasn't the case.

    Fortunately, I tried the following code, witch worked fine:

    "fnInitComplete": function(oSettings, json) {
        var api = this.api();
        $('#datatable_filter input')
            .off('.DT')
            .on('keyup.DT', function (e) {
                if  (e.keyCode == 13) api.search(this.value).draw();
            });
        }
    });
    

    Now, using this code, my search input is searching only on Enter Key. Just don't know why the fnFilterOnReturn is not working as well.

    Thanks anyway. Will continue here to fully integrate Editor in my admin panel.

    Sérgio Ávila

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    fnFilterOnReturn is a legacy API method so it needs to be initialised using the $().dataTable() (note the lowercase d) method.

    What you could do is:

    var table = $(...).DataTable( ... );
    
    $(...).dataTable().fnFilterOnReturn();
    

    Its not ideal and really that plug-in should get updated to use the more modern API. Thanks for pointing that out.

    I reckon the solution you've written above is probably better that using the workaround I've just written!

    Allan

This discussion has been closed.