col*_*lin 9 jquery filter datatables drop-down-menu
我正在使用dataTables jQuery插件(这非常棒),但是根据我的选择框的更改,我无法让我的表进行过滤.
功能:
$(document).ready(function() {
$("#msds-table").dataTable({
"sPaginationType": "full_numbers",
"bFilter": false
});
var oTable;
oTable = $('#msds-table').dataTable();
$('#msds-select').change( function() {
oTable.fnFilter( $(this).val() );
});
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<table border="0" cellpadding="0" cellspacing="0" id="msds-table">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>etc</th>
</tr>
</thead>
<tbody>
<select id="#msds-select">
<option>All</option>
<option>Group 1</option>
<option>Group 2</option>
<option>Group 3</option>
<option>Group 4</option>
<option>Group 5</option>
<option>Group 6</option>
</select>
<tr class="odd">
<td>Group 1</td>
<td><img src="images/modules/download-icon.gif" width="12" height="17" alt="" /></td>
<td><a href="#">Download</a></td>
</tr>
<tr class="even">
<td>Group 1</td>
<td><img src="images/modules/download-icon.gif" width="12" height="17" alt="" /></td>
<td><a href="#">Download</a></td>
</tr>
<tr class="odd">
<td>Group 1</td>
<td><img src="images/modules/download-icon.gif" width="12" height="17" alt="" /></td>
<td><a href="#">Download</a></td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
表继续显示一堆项目,直到"Group 6",但你明白了.有没有人试过这样做过?
Def*_*ity 11
我知道我以前做过这个,你必须看一下这条小信息:
请注意,如果您希望在DataTables中使用过滤,则必须保持"true" - 要删除默认过滤输入框并保留过滤功能,请使用 sDom.
你需要设置{bFilter:true},并将你移动<select></select>到通过sDom注册的自定义元素.我猜你的代码看起来像这样:
$(document).ready(function() {
$("#msds-table").dataTable({
"sPaginationType": "full_numbers",
"bFilter": true,
"sDom":"lrtip" // default is lfrtip, where the f is the filter
});
var oTable;
oTable = $('#msds-table').dataTable();
$('#msds-select').change( function() {
oTable.fnFilter( $(this).val() );
});
});
Run Code Online (Sandbox Code Playgroud)
根据文档,您的代码oTable.fnFilter( $(this).val() );不会触发{bFilter:false};
| 归档时间: |
|
| 查看次数: |
44476 次 |
| 最近记录: |