Search code examples
javascriptjquerytablesorter

assigning tablesorter filter value via javascript change event. works first time. on subsequent tries filter value reverts when executing update


The first time I select an entry the value is inserted into the filter of the first field of the table and the "update" causes the filter to work correctly.

If I then select a different entry, the correct value is assigned to the filter, but upon executing the "update", the value reverts to it's previous value.

Can anyone point me to a quick solution for this?

<select id="adminresources_mobilenumber_select" onchange="alert(this.value);esn_select(this.value)" name="mobile_number">


function esn_select(resource_id) {
    $(".tablesorter-filter").each(function () {
        var val = this.getAttribute("data-column");
        if (val == "0") {
            this.value = resource_id;
            $("table.tablesorter").trigger("update");
        }
    });
}

Solution

  • I just discovered that if I use the "search" trigger rather than the "update" trigger, it works correctly every time.

    I discovered this option on this fiddle example http://jsfiddle.net/LYyvp/15/

    function esn_select(resource_id) {
        $(".tablesorter-filter").each(function () {
            var val = this.getAttribute("data-column");
            if (val == "0") {
                this.value = resource_id;
                $("table.tablesorter").trigger("search");
            }
        });
    }