Adding .change() to filter input

Adding .change() to filter input

bcraigbcraig Posts: 8Questions: 2Answers: 0
edited June 2014 in Free community support

With my filter input for my datatable I have suggestions that appear below on .keyup() such like autocomplete. When clicking on a suggestion this changes the value of the filter input. How can I attach this event to update my datatable?

$('#filterInput').keyup(function(){
        if($(this).val().length !=0){
                $(this).next().fadeTo("slow", 1.0).css({cursor:"default"}); // fades in suggestion container
        suggestion(this, $(this).attr('tables')); // calls function that retrieves suggestions from database
        } else {
                $(this).next().fadeTo("slow", 0).css({cursor:"default"}); // input empty, no suggestions
    }
  });

Would I insert somewhere above: onchange - trigger filter update.

OR maybe I would put a trigger in my suggestion click function?

$(".suggestions").click(function(){
        $("#filterInput").value() = value;
        $('#filterInput').trigger('change');
});

    $('#filterInput').on('change', function() {
        var oTable = $('#table').dataTable();
        oTable2.fnDraw();
    });

OR would I add this trigger in the datatable call.. $('#table').DataTable();

Answers

  • bcraigbcraig Posts: 8Questions: 2Answers: 0

    This alert is actioned but table is not updated with the inputs new;y set value.

    $('#table').DataTable({""fnDrawCallback": function( oSettings ) {                                 alert( 'DataTables has redrawn the table' );
    }});
    
    $(".suggestions").click(function(){
        var parent = "#"+$(this).attr("parent");
        var suggestedValue = $(this).text();
        inputID.value = suggestedValue;
        $('#table').dataTable().fnDraw();
    });
    
  • bcraigbcraig Posts: 8Questions: 2Answers: 0
    edited June 2014

    Solved this myself..

    $(".suggestions").click(function(){
        $('#filterInput').trigger('keyup');
    }); 
    
This discussion has been closed.