autofocus input search

autofocus input search

FlavioC16FlavioC16 Posts: 3Questions: 1Answers: 0
edited July 2022 in Free community support

I would like to implement the "autofocus" function in the search field of my table, is this possible?

Answers

  • ItracItrac Posts: 12Questions: 1Answers: 0

    Check out this thread, especially Kevin's answer with the initComplete example.

  • FlavioC16FlavioC16 Posts: 3Questions: 1Answers: 0

    Thanks for replying, but I'm new in the area, this type of code "initComplete" is not working in httm5 in conjunction with javascript :(

  • kthorngrenkthorngren Posts: 21,449Questions: 26Answers: 4,975

    Please provide a link to your page or a test case showing the problem so we can help debug. You can update my below example.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Allan's solution in that thread works here:
    http://live.datatables.net/puxafaga/1/edit

    Kevin

  • FlavioC16FlavioC16 Posts: 3Questions: 1Answers: 0

    Thanks for helping with this issue, the issue was resolved this way.

    $(document).ready( function () {
    var table = $('#dataTable').DataTable();
    function foco(){
    $('div.dataTables_filter input', table.table().container()).focus();
    }
    setTimeout(foco, 1)
    });

  • djmcmdjmcm Posts: 2Questions: 0Answers: 0

    Does not work with version 2. Does anyone here have a solution?

  • kthorngrenkthorngren Posts: 21,449Questions: 26Answers: 4,975

    @djmcm

    I opened the test case I linked to above:
    http://live.datatables.net/puxafaga/1/edit

    And its working. Its using the Datatable nightly version which are the builds leading up to the next 2.x version. If this doesn't work for you then please post a link to a test case showing the issue. Possibly put the code in the ready() function so it executes after Datatables is fully ready.

    Kevin

Sign In or Register to comment.