Ahatius
Ahatius

Reputation: 4875

jQuery DataTables: Filter per column

I have a DataTables table, which is getting it's data trough an AJAX source. I've got the table up and running, even searching works.

Now I've got a request to implement search fields for every column. There seems to be a DataTables Plugin for column filtering, which I tried to use.

This is my HTML:

<!DOCTYPE HTML>
<html>
<head>
    <title>testpage</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
    <script type="text/javascript" src="http://www.company.com/content/dam/workflows/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="http://jquery-datatables-column-filter.googlecode.com/svn/trunk/media/js/jquery.dataTables.columnFilter.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $("#overview").dataTable({
            aoColumnDefs:[{
                aTargets: [0]
            }],
            bAutoWidth: false,
            bLengthChange: false,
            iDisplayLength: 10,
            sAjaxSource: "http://server/api.jsp?someparameters"
        }).columnFilter();
    })
    </script>
</head>

<body>

<table id="overview">
<tr>
    <thead>
        <th>#</th>
        <th>Betrieb</th>
        <th>Status</th>
        <th>Anlagenummer</th>
        <th>Bezeichnung</th>
    </thead>
</tr>
</table>

</body>
</html>

As you can see, I just attached the columnFilter() method. It doesn't even throw an error in the console, but the table looks just like before (no additional input boxes to search the columns).

Am I doing something wrong? Is it possible due to the source beeing AJAX?

Upvotes: 3

Views: 4383

Answers (1)

ducpn
ducpn

Reputation: 63

I think you need to define a footer section in your html table. Have a look at this example

The table should look like

<table>
    <thead>
        <tr>...</tr>
    </thead>
    <tfoot>
        <tr>...</tr>
    </tfoot>
</table>

Upvotes: 2

Related Questions