数据表在标题过滤器上添加自定义选择

时间:2016-06-06 12:02:33

标签: css filter datatables

我有这种类型的表格,带有自定义选择过滤器

https://jsfiddle.net/cvLdunzx/

<div class="col-lg-3 pull-right">
<select class="form-control">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
</div>

<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">

<thead>
    <tr>
        <th>Name</th>
        <th>Position</th>
        <th>Office</th>
        <th>Age</th>
        <th>Start date</th>
        <th>Salary</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>Tiger Nixon</td>
        <td>System Architect</td>
        <td>Edinburgh</td>
        <td>61</td>
        <td>2011/04/25</td>
        <td>$320,800</td>
    </tr>
    <tr>
        <td>Garrett Winters</td>
        <td>Accountant</td>
        <td>Tokyo</td>
        <td>63</td>
        <td>2011/07/25</td>
        <td>$170,750</td>
    </tr>
    <tr>
        <td>Ashton Cox</td>
        <td>Junior Technical Author</td>
        <td>San Francisco</td>
        <td>66</td>
        <td>2009/01/12</td>
        <td>$86,000</td>
    </tr>
    <tr>
        <td>Cedric Kelly</td>
        <td>Senior Javascript Developer</td>
        <td>Edinburgh</td>
        <td>22</td>
        <td>2012/03/29</td>
        <td>$433,060</td>
    </tr>

</tbody>
</table>

var table = $('#example').DataTable();

我想像这样显示自定义选择近搜索框

http://s33.postimg.org/x6vh0o9ov/img.png

如何添加到table_wrapper&gt; table_filter?

1 个答案:

答案 0 :(得分:2)

您可以使用dom / sdom属性自定义它。

https://datatables.net/reference/option/dom

你可以做一些事情:

 $('#example').DataTable( {
        responsive: true,
       "dom": '<"wrapper"f<"test">lipt>' // creates a div with class test
    } );
 $('.test').append("<select><option>1</option></select>");

https://jsfiddle.net/calinaadi/n8m0a49p/1/