3

我有一个 DataTables 表,它通过 AJAX 源获取数据。我已经启动并运行了表,甚至搜索工作。

现在我有一个要求为每一列实现搜索字段。似乎有一个用于列过滤的 DataTables 插件,我尝试使用它。

这是我的 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>

如您所见,我刚刚附加了 columnFilter() 方法。它甚至不会在控制台中引发错误,但表格看起来就像以前一样(没有额外的输入框来搜索列)。

难道我做错了什么?是否有可能是由于 AJAX 的来源?

4

1 回答 1

2

我认为您需要在 html 表中定义一个页脚部分。看看这个例子

表格应该看起来像

<table>
    <thead>
        <tr>...</tr>
    </thead>
    <tfoot>
        <tr>...</tr>
    </tfoot>
</table>
于 2013-04-05T12:32:51.687 回答