使用 Jquery 数据表过滤 Ajax 填充的数据时出现问题

发布于 2024-10-28 01:36:50 字数 1438 浏览 1 评论 0原文

我有一个使用以下代码的 jquery 数据表:

// Test list table
$('#dashboard_testlist_table').dataTable({
    "bJQueryUI": true,
    "bAutoWidth": false,
    "bProcessing": true,
    "aaSorting": [[0, 'asc'], [2, 'asc']],
    "sPaginationType": "full_numbers",
    "sAjaxSource": projectTestListTablePopulateUrl,
    "oLanguage": {
        "sSearch": "Search all columns:"
    },
    "aoColumns": [{
        "sTitle": "Protocol/Test/Case"
    }, {
        "sTitle": "Last Run"
    }, {
        "sTitle": "Last Build/Phase"
    }, {
        "sTitle": "Detail",
    "sClass": "center"
    }, {
        "sTitle": "Owner"
    }]
});  

我的服务器正确发回 JSON,并且该表按预期填充。

我遇到的问题是我无法在表中进行任何过滤。搜索框中的任何字符都会立即过滤,不显示任何结果。我使用过很多数据表,而这个让我发疯。

我注意到,当我“查看页面源代码”时,源代码中没有呈现的 html。这是我的原始 HTML:

<!--Test List Table-->
<table id="dashboard_testlist_table" class="display">
<!--Table Header-->
<thead>
    <tr>
        <th>Protocol/Test/Case</th>
        <th>Last Run</th>
        <th>Last Build/Phase</th>
        <th>Detail</th>
        <th>Owner</th>
    </tr>
</thead>

<tbody>
<!--Table Body, ajax populated, see /media/custom_js/user_dashboard.js -->
</tbody>
</table>

页面加载后,它仍然显示相同的内容。发送的 JSON 数据是否应该填充在那里?

否则,有人对过滤这些数据时首先要寻找什么有任何建议吗?我正在使用 jquery 数据表 1.6.2。

I have a jquery datatable using the following code:

// Test list table
$('#dashboard_testlist_table').dataTable({
    "bJQueryUI": true,
    "bAutoWidth": false,
    "bProcessing": true,
    "aaSorting": [[0, 'asc'], [2, 'asc']],
    "sPaginationType": "full_numbers",
    "sAjaxSource": projectTestListTablePopulateUrl,
    "oLanguage": {
        "sSearch": "Search all columns:"
    },
    "aoColumns": [{
        "sTitle": "Protocol/Test/Case"
    }, {
        "sTitle": "Last Run"
    }, {
        "sTitle": "Last Build/Phase"
    }, {
        "sTitle": "Detail",
    "sClass": "center"
    }, {
        "sTitle": "Owner"
    }]
});  

My server sends back the JSON correctly and the table populates as expected.

The problem that I am having is that I can not do any filtering whatsoever in my table. Any character in the search box immediately filters to no results being displayed. I have used many datatables and this one is driving me crazy.

I have noticed that when I "View Page Source", there is no rendered html in the source. Here is my original HTML:

<!--Test List Table-->
<table id="dashboard_testlist_table" class="display">
<!--Table Header-->
<thead>
    <tr>
        <th>Protocol/Test/Case</th>
        <th>Last Run</th>
        <th>Last Build/Phase</th>
        <th>Detail</th>
        <th>Owner</th>
    </tr>
</thead>

<tbody>
<!--Table Body, ajax populated, see /media/custom_js/user_dashboard.js -->
</tbody>
</table>

After the page is loaded, it still shows the same. Is the JSON data that was sent supposed to be populated there?

Otherwise, does anyone have any suggestions on what to look for first with filtering this data? I am using jquery datatables 1.6.2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑红尘 2024-11-04 01:36:50

您是否在服务器端页面中使用了搜索查询,

例如这样

if ( $_GET['sSearch'] != "" )
{
    $sWhere = "WHERE engine LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "browser LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "platform LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "version LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "grade LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%'";


}

did u use search query in your server side page

exaple like this

if ( $_GET['sSearch'] != "" )
{
    $sWhere = "WHERE engine LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "browser LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "platform LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "version LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
                        "grade LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%'";


}
鹿港巷口少年归 2024-11-04 01:36:50

实际上,问题最终是我在 JSON(链接)中传递的一些 html,该 html 被放置到表中的一个 td 元素中。它畸形并引起头痛。

Actually, the problem ended up being some html that I was passing in the JSON (a link) that was placed into one of the td elements in the table. It was malformed and was causing the headache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文