簡體   English   中英

下拉列表中的事件更改調用自定義過濾功能(數據表)

[英]Call custom filtering function on event change in dropdown (dataTable)

我有一個自定義過濾功能,當下拉列表中的值更改時,我需要實現它。

function employee_filter(status){
$.fn.dataTable.ext.search.push(
        function( oSettings, aData, iDataIndex ) {
            // check if current table is part of the allow list
            if ( $.inArray( oSettings.nTable.getAttribute('id'), allowFilter ) == -1 )
            {
               // if not table should be ignored
               return true;
            }

           return aData[8] == status;
        }
);

table.draw();
}

HTML:

<form class="form-group">
  <select class="form-control" style="width: 25%;" id="employee_filter">
    <option value=1>Active Employees</option>
    <option value=0>Ex-Employees</option>
    <option value="">Show All Employees</option>
  </select>
 </form>

我添加了事件監聽器

$('select#employee_filter').change( function() { 
    employee_filter($(this).val()); 
} );

這是行不通的,我只是盡我所能。 請幫我任何建議:)

你可以試試這個嗎?

$(document).on( "change" , "select#employee_filter" , function(){
    employee_filter($(this).val()); 
});

另外,什么不起作用? 它返回值嗎? 還是不更新表?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM