【问题标题】:Trouble Filtering With Ajax-populated Data with Jquery Datatables使用 Jquery 数据表过滤 Ajax 填充的数据时遇到问题
【发布时间】:2011-03-28 15:24:19
【问题描述】:

我有一个使用以下代码的 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。

【问题讨论】:

    标签: jquery ajax datatables


    【解决方案1】:

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

    比如这样

    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'] )."%'";
    
    
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2017-05-01
        • 2013-09-28
        • 2020-08-22
        • 2011-10-30
        • 2021-04-13
        • 2018-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多