Filter not removed when user clicks "X" in search box (Internet Explorer only)

Filter not removed when user clicks "X" in search box (Internet Explorer only)

d0tingd0ting Posts: 1Questions: 0Answers: 0

No need for an answer or solution here (although this might be a DataTables bug).

We had a problem in Internet Explorer where users could clear the search box by clicking the "X" in the search box, but the filter was not cleared in the DataTable. That is, after clicking the "X", the filtered results remained visible in the DataTable.

The following JavaScript solved the problem for us, and may be helpful for others. The script is executed within the document.ready function. The offsetX value was determined by observing the leftmost value where the user could successfully click the "X", and the value might need to be adjusted per other environments.

Browser: Internet Explorer 11
DataTables version: 1.10.12

//This event handler is a hack for Internet Explorer.
//In Chrome, the filter is cleared automatically when user clicks "X" in the search box.
//(Maybe this is because the click event is exposed in Chrome for this user action, and
//is not exposed in Internet Explorer. Or, maybe it's related to the fact that
//the DataTables search box is rendered as input type="search" in Chrome but rendered as 
//input type="text" in Internet Explorer.)
$('#dataGrid_filter input[type=text]').mouseup(function (e) {
    if (e.offsetX > 137) {
        var tbl = $("#dataGrid").DataTable();
        tbl.search('').columns().search('').draw();
    }
});

Replies

  • allanallan Posts: 63,280Questions: 1Answers: 10,425 Site admin

    I don't seem to be having that issue I'm afraid. With this example and IE11, if I type some text into the search box and then click the clear button, the filter is cleared from the table.

    Allan

  • TELE2_NL2TELE2_NL2 Posts: 17Questions: 2Answers: 0

    In the above examplehttps://datatables.net/examples/basic_init/zero_configuration.html in IE i am not able to see the 'X' option itself after search the results.

  • allanallan Posts: 63,280Questions: 1Answers: 10,425 Site admin

    It is dependant on your operating system as well as browser version. What OS and version of IE are you using?

    Allan

  • TELE2_NL2TELE2_NL2 Posts: 17Questions: 2Answers: 0

    windows 7 operating system and IE 11 Browser

  • allanallan Posts: 63,280Questions: 1Answers: 10,425 Site admin

    If you have a simple <input type="search"> HTML element on a simple HTML page, does it show up then? It might have been added in Win8 - I can't remember? Either way, it isn't something that DataTables adds, but its a native UI control from the OS.

    Allan

This discussion has been closed.