【问题标题】:Bootstrap table showing empty rows显示空行的引导表
【发布时间】:2017-07-14 16:06:26
【问题描述】:

我创建了这个从 .PHP 文件填充数据的引导表,但是我无法让格式看起来正确,见下文:

Table with extra spacing

表格底部添加了许多额外的行,并在其下方显示“表格中没有可用数据”。

有人可以告诉我如何解决这个问题吗??

HTML:

<div class="row">
    <div class="col-md-12">
        <div class="box box-primary">
            <div class="box-header">
                <h3 class="box-title">Existing Log Entries</h3>
            </div>

            <form role="form">
                <div class="box-body">
                    <div class="col-md-12" id="div-log-list">
                    </div>
                </div>
                <div class="box-footer">
                </div>
            </form>


            <table id="entrieslist" class="table table-bordered table-striped dataTable">
                <thead>
                    <tr>
                        <th>Date/Time</th>
                        <th>Server Name</th>
                        <th>Carried Out By</th>
                        <th>Verified By</th>
                        <th>Authorised By</th>
                        <th>Work Carried Out</th>
                        <th>Work Verification</th>
                        <th>Change Reason</th>
                        <th>Perceived Impact</th>
                        <th>Rollback Process</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th>Date/Time</th>
                        <th>Server Name</th>
                        <th>Carried Out By</th>
                        <th>Verified By</th>
                        <th>Authorised By</th>
                        <th>Work Carried Out</th>
                        <th>Work Verification</th>
                        <th>Change Reason</th>
                        <th>Perceived Impact</th>
                        <th>Rollback Process</th>
                    </tr>
                </tfoot>
            </table>



        <div class="overlay" id="box-loading">
          <i class="fa fa-refresh fa-spin"></i>
        </div>




        </div>
    </div>
</div>

Javascript:

// Cell spacing for log entry table
document.getElementById("entrieslist").style.borderSpacing = "10px";

// Populates log entry table
$.ajax({
    type: "post",
    url: "ajax/ajax-process-log-entry.php", 
    success: function(result){
        $('#entrieslist tfoot:last').after(result);
        $('#box-loading').hide();
        $("#entrieslist").dataTable();


    }
}); 

PHP:

// List existing server log entries
$stmt = $db->prepare("SELECT * FROM [ralanet].[dbo].[server_log_entries] (nolock)");

$stmt->execute();
$lines = $stmt->fetchAll(PDO::FETCH_ASSOC);



$counter = 0;
foreach( $lines as $row) {
echo '<tr>';
echo        '               
        <td>'.$row['date_time'].'</td>
        <td>'.$row['server_name'].'</td>
        <td>'.$row['carried_out_by'].'</td>
        <td>'.$row['verified_by'].'</td>
        <td>'.$row['authorised_by'].'</td> 
        <td>'.$row['work_carried_out'].'</td>
        <td>'.$row['work_verified'].'</td>
        <td>'.$row['change_reason'].'</td>
        <td>'.$row['perceived_impact'].'</td>
        <td>'.$row['rollback_process'].'</td>
            ';
echo '</tr>';}
$counter++;

$db = null;

【问题讨论】:

    标签: javascript php html css bootstrap-table


    【解决方案1】:

    把表结构改成

    <table>
        <thead></thead>
        <tbody></tbody>
        <tfoot></tfoot>
    </table>
    

    然后输入你的结果,例如,

    $.ajax({
        type: "post",
        url: "ajax/ajax-process-log-entry.php", 
        success: function(result){
            $('#entrieslist tbody').html(result);
            $('#box-loading').hide();
            $("#entrieslist").dataTable();
    
    
        }
    }); 
    

    【讨论】:

    • 嗨 Av,感谢您的回复,我尝试了您的解决方案,它与 Mark 所做的相同,请参阅下面的评论和屏幕截图:link。数据仅显示在最后一页。感谢您迄今为止的帮助!
    • 先删除表格内容$("#entrieslist tbody").html();
    • 我用$("#entrieslist tbody").html(); 替换了$('#entrieslist tbody').html(result);,这是我假设你要我做的,这返回了一个没有结果的空白表
    • 抱歉,$("#entrieslist tbody").html(''); 在发送 ajax 之前
    • 感谢您的帮助!您的解决方案确实有效 - 我的 SQL 表中有大量空白行,每次加载页面时都会运行另一个 .php 文件并在其中输入空白行...
    【解决方案2】:

    尝试将&lt;tbody&gt;&lt;/tbody&gt;放在theadtfoot之间,然后将结果放入tbody
    替换$('#entrieslist tfoot:last').after(result); $('#entrieslist tbody').html(result);

    【讨论】:

    • 嗨,马克,感谢您的回复,由于某种原因,页面现在看起来像这样:link。数据显示,但仅在表格结果的最后一页显示,如果将其与原始屏幕截图进行比较,它也会使表格看起来块状。感谢您迄今为止的所有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 2016-03-02
    • 2017-02-07
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    相关资源
    最近更新 更多