How do I add a Button Collection to display menu items to add to search query

How do I add a Button Collection to display menu items to add to search query

BrettABrettA Posts: 12Questions: 4Answers: 0

So I have finally worked out how to display a custom button collection with 3x buttons. (Showing my level of skill here).
What I would like is for the items in the button collection to send search query terms to the main Search box.
So click on the Accounting button, and "Accounting" is stamped in the search box.

Can someone please provide a code sample I could use, perhaps in the action: function (...) for each button?
I've read everywhere, but can't seem to locate ow to do this.
Much appreciated.

This question has an accepted answers - jump to answer

Answers

  • BrettABrettA Posts: 12Questions: 4Answers: 0

    For further info, this is my button code: it filters the table but I need to stamp the search query into the Search box.

     buttons: [
            {
                extend: 'collection',
                text: 'Context',
                autoClose: true,
                buttons: [
                    { text: 'HR',   action: function(e, dt, node, config){
                    dt.column(3).search("HR").draw();}},
                    { text: 'BD',  action: function(e, dt, node, config){
                    dt.column(3).search("BD").draw();}},
                    { text: 'Operations', action: function(e, dt, node, config){
                    dt.column(3).search("Operations").draw();}}
                ],
                fade: true
            }
        ],
    
    

    The search box uses a query string url, so the URL can be emailed if required.
    Thanks.

  • colincolin Posts: 15,238Questions: 1Answers: 2,599
    edited June 2018 Answer ✓

    Hi @BrettA ,

    It's just a case of changing your dt.column(3).search(), to be dt.search(). If you do a global search(), the search term is entered automatically into the search field.

    Cheers,

    Colin

  • BrettABrettA Posts: 12Questions: 4Answers: 0

    Thanks Colin, I was almost there but it would taken me all day to work that one out, much appreciated.

This discussion has been closed.