【问题标题】:DataTable plugin not working with dynamically generated php table (arrows wouldn't show up too)DataTable 插件不适用于动态生成的 php 表(箭头也不会出现)
【发布时间】:2013-08-09 18:06:22
【问题描述】:

我使用 php 创建了一个表并添加了插件(使用 demo_table.css)。箭头不会显示在结果页面上,也不会应用任何 css。

这是我的 php 代码:

        $result = mysqli_query($link, $sql);

$num_rows = mysqli_num_rows($result);
        echo '<table cellpadding = "0" cellspacing="0" border="0" id="datatables"  class="display">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>SNo.</th>
        <th>Username</th>
        <th>Trip ID</th>
        <th>Destination</th>
        <th >Leave Date</th>
        <th>Return Date</th>
        <th>Total</th>
        <th>Submit Date</th>
        <th >Status</th>
        <th >Reason</th>
        <th >Update</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';

}       else {
            echo('not valid user');
        }

if (!$result) {
    die(mysqli_error($link));

    }

if ($num_rows<=0){
    echo('not valid user');
    }

    elseif ($num_rows>0){
        $i=1;
        while($row = mysqli_fetch_assoc($result)) {

                $grandtotal = $row['flight_estimate'] + $row['registration_fee'] + $row['total_cost'];
                $status = $row['status'];
                if(($status == 'Approved') || ($status == 'Denied')){
                    $newcolumn = '<td></td>';
                }
                else{
                    $newcolumn = '<td><a href="Adminview.php?trip_id=' . $row['trip_id'] . '" id="editlink">Approve/Deny</a></td>';

                }

                echo '<tr>';
                echo '<td>'. $i++ .'</td><td>'.$row['username'].'</td><td>'.$row['trip_id'].'</td><td>'.$row['destination'].'</td><td>'.date('d/m/Y',strtotime($row['leave_date'])).'</td><td >'.date('d/m/Y',strtotime($row['return_date'])).'</td><td >'. round($grandtotal,2).'</td><td >'.date('d/m/Y',strtotime($row['updateddate'])).'</td><td >'.$row['status'].'</td><td >'.$row['reason'].'</td>'.$newcolumn;
            }
    echo '</tr>';
    echo '</tbody>';
    echo '</table>';

} ?>

我有什么遗漏的吗?它所做的只是将所有列值居中。但是当我点击标题时没有任何反应。

【问题讨论】:

  • 我会先清理一下所有这些条件,你可能不需要它们。现在, elseif 有空间,你写的没有。否则如果()。
  • 你在哪里初始化数据表?
  • @davidkonrad 我的主页中有一个单独的脚本文件。这是其中的一部分:$(document).ready(function() { $("#datatables").dataTable( ); });

标签: php jquery jquery-plugins datatables


【解决方案1】:

你需要在初始化dataTable时将'bJQueryUI'设置为true

$("#datatables").dataTable({ 'bJQueryUI' : true });

如果你发布你的 js 脚本会有所帮助,因为那是你的问题所在。

【讨论】:

    猜你喜欢
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多