Search box getting focus without me setting it

Search box getting focus without me setting it

KanthKanth Posts: 20Questions: 9Answers: 0
edited March 2019 in DataTables 1.10

I have a DataTable, loading from the server during $(document).ready. The page has a lot of content on it so when the page initally loads, the DataTable is below the bottom of the screen. For some reason, the search box gets focus even though there are a bunch of inputs above it on the page. So, this causes the page to scroll down to the DataTable just enough to have the Search Box on screen. There is no code to set the focus there. If I change the DOM and remove the "f", it doesn't scroll because it isn't there (obviously). I cannot figure out how it is doing this! What else can cause the search box to gain focus?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @Kanth ,

    By default, the initialisation doesn't set the focus on the search input, you can see that by trying the examples. I'm not sure how you can tell which script is causing - maybe try looking at the events on the page.

    Hope that helps,

    Colin

  • KanthKanth Posts: 20Questions: 9Answers: 0
    edited March 2019

    Thanks @Colin. As it turns out, there was a Custom User Control with a DataTable in it that was calling

    $('div.dataTables_filter input').focus();
    

    on the initComplete. The browser, I suppose, just chose the latest one to focus on.

This discussion has been closed.