1
我有一个约30000行的mysql表。我必须将所有行放入DataTable中,并在每次加载表页时加载每个段(当您单击分页时)。我看到我可以在我的JS中使用deferLoading参数,但是当我使用它时,我的页面没有加载。正如你所看到的,我需要加载图片,所以我绝对有做内容的轻负载...DataTables:延迟加载无法正常工作
这里是我的HTML:
<table class="table table-striped table-bordered table-hover datatable products-datatable">
<thead>
<tr>
<th></th>
<th><?=_("Product")?></th>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th><?=_("Product")?></th>
<th></th>
</tr>
</tfoot>
</table>
这里是我的JS:
var table = $('.products-datatable').dataTable({
"order": [[ 1, "asc" ]],
"processing": true,
"serverSide": true,
"deferLoading": 30000,
"ajax": {
url: location.protocol + '//' + location.hostname + '/ajax/products.php?action=list',
type: "POST"
},
"columns": [
{ "data": "image",
"orderable": false,
"width": "80px" },
{ "data": "product" },
{ "data": "action",
"orderable": false,
"width": "20px",
"sClass": "class",
}
]
});
这里是我的AJAX:
$req = $pdo->prepare('SELECT product_id, name FROM products');
if ($req->execute()) {
if ($req->rowCount()) {
$result['draw'] = 1;
$result['recordsTotal'] = $req->rowCount();
$result['recordsFiltered'] = 10;
$result['data'] = array();
$result['DT_RowId'][] = array();
while($row = $req->fetch()) {
if ($row['name']) { $name = $row['name']; } else { $name = "N/A"; }
$result['data'][] = array( "DT_RowId" => $row['product_id'],
"DT_RowClass" => 'myclass',
"image" => '<a href="' . HOSTNAME._("product").'/'.$row['product_id'] . '"><img src="' . HOSTNAME.'assets/img/products/' . $row['product_id'] . '.jpg" class="product_thumb"></a>',
"product" => '<a href="' . HOSTNAME._("product").'/'.$row['product_id'] . '">' . $name . '</a>',
"action" => "<a href=\"#\" class=\"button-delete\" id=\"" . $row['product_id'] . "\"><i class=\"fa fa-close fa-2x text-danger\"></i></a>"
);
}
}
}
$req->closeCursor();
我敢肯定有东西,我错过了...... :-(
非常感谢! –