Assign ID to Global Search Box

Assign ID to Global Search Box

jkallajkalla Posts: 6Questions: 2Answers: 0

Description of problem: I'm trying to figure out how to assign an ID to the global search box, either in the javascript or on the page html. I found an answer for using Selenium, but not something that allows me to change it in the script. Here's what I have for script at this time:

$(document).ready( function () {
    $('#myTable').DataTable({
        language: {
            search: "Filter records: "
        },
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ],
        bLengthChange:true,
        bInfo:true,
        bPaginate:true,
        order: [[2, "desc"]],
        search: {
            return: false
        }
    });
} );

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Add this to your table initialisation object:

    initComplete: function () {
      $('div.dataTables_filter input', this.api().table(). container()).attr('id', 'myId');
    }
    

    Out of interest, why do you need to do this?

    Allan

  • jkallajkalla Posts: 6Questions: 2Answers: 0
    edited November 2023

    What I'm actually trying to do is send a URL to the page with ?searchID=mytext at the end of it. If there's an easy way to do this, I can't figure it out. I was hoping to pre-search the table on the page.

    Unfortunately, I have no idea what a 'table initialisation object' is. Sry. The code is just included in the page.

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited November 2023 Answer ✓

    What I'm actually trying to do is send a URL to the page with ?searchID=mytext at the end of it.

    Sounds like you want to use the Deep linking plugin.

    Unfortunately, I have no idea what a 'table initialisation object' is.

    That is the code in lines 3-16 in your above code snippet. Its a Javascript object passed to the $('#myTable').DataTable( ) function call.

    Kevin

  • jkallajkalla Posts: 6Questions: 2Answers: 0

    Thanks, @kthorngren! I was able to get it to work using deep linking. Now I just have to figure out how to stop initializing the table twice. :)

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    If you show us your code, we should be able to help with that.

    Allan

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    Doh. I've just seen your other thread on that topic and that Kevin has already replied!

    Allan

Sign In or Register to comment.