[英]dataTable search[Filter Plugin] doesn't work until change
This is kind of a strange question, but this requirement came up about showing only those values inside a table which were selected using a dropdown list, I used dataTable plugin to display this data and to achieve the requirement I used the search[Filter plugin] feature. 这是一个奇怪的问题,但是这个要求是关于仅显示使用下拉列表选择的表中的值,我使用dataTable插件显示此数据并达到使用search [Filter plugin]的要求特征。 So whenever I selected any value from my dropdown list I entered it in the search input tag of dataTable. 因此,无论何时从下拉列表中选择任何值,我都将其输入到dataTable的搜索输入标记中。 However, filtering of the data would not occur unless I changed the added data myself. 但是,除非我自己更改添加的数据,否则不会进行数据过滤。
Have used the following script to add the selected value in the search box of DataTable; 使用以下脚本在DataTable的搜索框中添加所选值; this function is triggered using onchange in the HTML tag: 此功能是使用HTML标签中的onchange触发的:
function changeService(val) {
var service = val;
$('#example_filter').find('input').val(service);
}
This function adds the value in the required search input tag - I can see the value in the textbox; 此函数将值添加到所需的搜索输入标签中-我可以在文本框中看到该值; but the data within the dataTable is not filtered until I change this... 但是在我更改此数据表之前,不会过滤dataTable中的数据...
Instead of trying to hack around the ui, why not use the DataTables api for this: 与其尝试绕过ui,不如使用DataTables api:
http://datatables.net/api#fnFilter http://datatables.net/api#fnFilter
So when you're dropdown list changes, you could call the fnFilter function on your datatable: 因此,当下拉列表更改时,可以在数据表上调用fnFilter函数:
$('#dropdownlist').on('change', function() {
var val = $(this).val();
var dataTable = $('#table').dataTable();
dataTable.fnFilter(val);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.