How to clear the search input from outside of DataTables

How to clear the search input from outside of DataTables

lorikay4lorikay4 Posts: 18Questions: 4Answers: 1
edited November 2015 in Free community support

I have a DataTable that lives inside of a jquery dialog box.

When users click on a link in the table, I have jquery that loads an image and closes the dialog box.

If the users re-open the dialog without reloading the page, whatever search performed the last time the dialog was open and the table was visible is still applied.

Is there a way to clear the search box (both emptying the search input and re-displaying any hidden rows in the table) via a jquery command?

This question has an accepted answers - jump to answer

Answers

  • lorikay4lorikay4 Posts: 18Questions: 4Answers: 1
    edited November 2015

    I tried to post a code sample, but I couldn't make it look readable. What the heck?

  • allanallan Posts: 63,099Questions: 1Answers: 10,391 Site admin

    Details on code formatting are shown below the buttons for the input - see this page for examples.

    Assuming you are applying a search using the API then it can also be cleared using the API (search() with an empty string). However, without a link to a test case I can't say much more than that.

    Allan

  • lorikay4lorikay4 Posts: 18Questions: 4Answers: 1

    Go here: http://www.star.nesdis.noaa.gov/icvs-beta/status_NPP_sc_test.php

    Click the button in the upper right labeled "Metrics Finder"

    The table that pops up in the dialog is a DataTable instance. When users click on a link in the table, an image loads, the dialog box is closed, and I want to clear search at that point.

  • allanallan Posts: 63,099Questions: 1Answers: 10,391 Site admin

    Did you try calling the search() method and then draw() (i.e. table.search('').draw();? You need to call draw() to update the table as the documentation explains.

    Allan

  • lorikay4lorikay4 Posts: 18Questions: 4Answers: 1
    edited November 2015

    The relevant script bit is:

    function GTSO(param,specific) {  // GTSO = goToSelectOption
        $("#parameter").prop("selectedIndex", param); 
        paramSelectedValue = document.getElementById('parameter')[param].value;
            showParams();       // make the selected box visible?
        secondSelectBoxID = paramSelectedValue.substring(0,9);
        $('#' + secondSelectBoxID).prop("selectedIndex", specific);
            $('#' + secondSelectBoxID).prop("selectedIndex", specific).trigger('change'); // execute the select box-driven action
            // clear the datatables filtering search box?
             $('input[type=search]').val('');  // this line and next one clear the search dialog
            $('#finderDialog').dialog('close');  // close the popup dialog box;
    }
    

    Can these methods you reference be called from inside this script? That's what I need to be able to do.

  • allanallan Posts: 63,099Questions: 1Answers: 10,391 Site admin

    Can these methods you reference be called from inside this script?

    Sure - the API manual describes how to access the API.

    I guess another option would be to trigger the change event on the input element:

    $('input[type=search]').val('').change();
    

    I would suggest you use the API as I suggested above, but that would also work.

    Allan

  • lorikay4lorikay4 Posts: 18Questions: 4Answers: 1

    that does work. The part I can't get to work is applying the "" value to the search.

  • lorikay4lorikay4 Posts: 18Questions: 4Answers: 1

    ok, finally understand, it works.

    I have a request: when I search your site / documentation for information, there is no way to say "only show me content from version 1.10 or later". I get results from older versions of the product constantly, which I know don't apply, but there is no good way to filter my results to only get answers that are relevant to the latest version of DataTables. If there was a way to do that, I would have been much better able to figure this out myself.

  • allanallan Posts: 63,099Questions: 1Answers: 10,391 Site admin

    If the page looks ugly then it is old - and should have a nice big notice at the top stating that. In the forum legacy information should also have a notice.

    The reference contains 1.10+ information.

    An improved site search is something I know needs to be added. The current Google custom search really isn't great.

    Allan

  • lorikay4lorikay4 Posts: 18Questions: 4Answers: 1

    Allan -- thanks. My datatables implementation is now working gangbusters, thank you so much for this very useful suite of tools.

    If you go here:
    http://www.star.nesdis.noaa.gov/icvs-beta/status_NPP_CrIS.php
    and click the 'Finder' button in the upper right, it pops up a dialog with a generated datatable that lets users search the page for desired satellite metrics. click the link, and the desired metric is displayed, the dialog box closes.

    I know which pages are and are not 1.10 information, I just wish I could limit my search to them, to make it faster to find things.

  • allanallan Posts: 63,099Questions: 1Answers: 10,391 Site admin
    Answer ✓

    That's a really nice use of DataTables - thanks for showing me!

    I've got a book on Sphinx on my desk waiting for me to get to grips with the site's search. Hopefully, since the data is structured it should perform quite well (once done...).

    Allan

This discussion has been closed.