首页 > 解决方案 > PHP Datables 没有显示任何行 - 服务器端

问题描述

我无法让 Datables 正常工作。

无论我尝试什么,我都会遇到没有数据的问题。确切的消息是:“没有找到匹配的记录”。

我使用的是官方网站上的正确格式但似乎不想加载。

我没有使用 MYSQL,所以没有包含任何 SPP,但我只是在数组中返回地址数组,然后将其编码为 JSON。

在我的前端文件中,我试图从某个路由器加载所有地址:

<script type="text/javascript">
$(document).ready(function() {
    $('#table').DataTable({
        "serverSide": true,
        "processing": true,
        "ajax": {
            "url": "<?=url('database/addresses');?>",
            "dataSrc": "",
        },
      'columnDefs': [{
          'targets': 1,
          'checkboxes': {
             'selectRow': true
          }
      }],
      'select': {
          'style':    'multi',
          'selector': 'td:first-child'
      },
      'order': [[5, 'desc']],
        "columns": [
            { "data": "id" },
            { "data": "id" },
            { "data": "input_address" },
            { "data": "destination_address" },
            { "data": "callback_url" },
            { "data": "dateCreated.date" },
            { "data": "id" }
        ],
        'colReorder': true
    });
} );
</script>

我的html表:

 <form method="post" id="deleteMulti" class="ajax-multi" action="<?=url('XhPCrvFtQuE7gPP6/addresses/delete/selected');?>">
    <?= csrf() ?>
        <div class="row">
            <div class="col-xxl-12">
                <div class="card">
                    <div class="card-header">
                        <h4 class="card-title">Addresses [ <?=$count;?> ]</h4>
                        <div class="right fr">
                            <button class="btn tooltip" style="display: inline;" name="deleteSelected" title="Delete Selected Addresses"><i class="fa fa-trash" style="color: black;"></i></button>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table id="table" class="display">
                               <thead>
                                  <tr>
                                    <th>#</th>
                                    <th><input type="checkbox" class="" id="checkAl"></th>
                                    <th>Input Address</th>
                                    <th>Output Address</th>
                                    <th>Callback Url</th>
                                    <th>Created</th>
                                    <th><i class="bi bi-archive-fill"></i></th>
                                  </tr>
                               </thead>
                               <tfoot>
                                  <tr>
                                     <th></th>
                                     <th></th>
                                     <th></th>
                                     <th></th>
                                     <th></th>
                                     <th></th>
                                     <th></th>
                                  </tr>
                               </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
**并在我的数据库/地址中加载数据库内容:**
// This is used for when we need to load more address's to the admins /addresses page
public function getAddresses() {
    define('PAGE_NAME', 'Admin Addresses');

    // Skip 100 as we will start from the 100th row
    // We set the limit to 100 in Admin page so the page loads 100 much faster
    // We will push more and more using this function inside here for when they click load more
    $addresses = \r\table('addresses')->orderBy(array('index' => \r\desc('dateCreated')))->skip(100)->limit(100)->run($this->conn);
    $addresses = $addresses->toArray();

    $count = count($addresses);

    $theArr = array();

    foreach ($addresses as $address) {
        $theArr[] = $address;
    }

    $final = array(
        'draw' => 1,
        'recordsTotal' => $count,
        'recordsFiltered' => $count,
        'data' => array_values($theArr)
    );

    if($count > 0) {
        echo json_encode($final, JSON_FORCE_OBJECT);
    } else {
        return false;
    }
}

我的问题是它不断向我显示: 即使我确实有超过 4k 条记录,也没有找到匹配的记录。

看看这张照片在这里

看看我的 getAddresses() 返回的 json 格式这里

标签: javascriptphpdatabase

解决方案


推荐阅读