How can I force a search by clicking a link a the datatable cell?

How can I force a search by clicking a link a the datatable cell?

pokerdawgpokerdawg Posts: 1Questions: 1Answers: 0

I'm setting up a data table that lists in separate columns:

Name, Email, Transaction Date, TransactionAmount

I want to make "email" a link (it is a unique field), so that when it is clicked, it replaces the value in the filter and the filter is redrawn.

I've been able to update the filter value, but I've tried dozens of permutations and can't get the filtering to re-trigger.

I am a relative newb with DataTables. if you could respond with an example that includes the table name and field name, that would be great.

ALSO, I would be fine with it filtering the whole table. I could not get that to work, and started experimenting with versions that filtered just one column. If you could provide the code that allows filtering all, that would be best.

Thank you!

function listfilter(thefilter) {

    // myTable7 already exists, I'm just referring to it here.
    var oTable = $('#myTable7').dataTable();

    // this successfully sets the value of the filter
    $("#myTable7_filter input[type=search]").each(function(index){
        $(this).val(thefilter);
    });

    // this does nothing, and breaks the JS
    oTable.columns([1]).search(this.value).draw();

    // the alert doesn't occur, indicating the step above failed
    alert('hi');

}

Answers

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Use search() to set the search able. The issue you are seeing (there will be an error in you browser's console) is the top FAQ :).

    Allan

This discussion has been closed.