[英]Why isn't the search function on my datatables.js working?
我正在按照網站上的說明制作一個CakePHP 2.x應用程序並安裝了datatables.js,但是盡管有,某些功能卻無法使用。 我無法更改要顯示的條目數,搜索功能始終不返回任何內容,也不會將數據拆分為多個頁面(例如,如果我將其設置為每頁顯示10個條目,它將仍然顯示所有內容在一頁上,即使超過10頁也是如此。
唯一起作用的部分是排序功能及其外觀。
這是我已在其上實現數據表的視圖:
<div class="products index">
<h2><?php echo __('Products'); ?></h2>
<table cellpadding="0" cellspacing="0" id="prod-tbl">
<thead>
<head>
<!--<script src="jquery-1.11.1.min.js"></script>-->
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.3/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.3/js/jquery.dataTables.js"></script>
<script >$(document).ready( function () {$('#prod-tbl').DataTable();} );</script>
</head>
<tr>
<th><?php echo $this->Paginator->sort('name'); ?></th>
<th><?php echo $this->Paginator->sort('product_code'); ?></th>
<th><?php echo $this->Paginator->sort('image_name'); ?></th>
<th><?php echo $this->Paginator->sort('image_url'); ?></th>
<!--<th><?php echo $this->Paginator->sort('brand_id'); ?></th>
<th><?php echo $this->Paginator->sort('reward_id'); ?></th>-->
<th><?php echo $this->Paginator->sort('product_status_id'); ?></th>
<th><?php echo $this->Paginator->sort('serial_id'); ?></th>
<th><?php echo $this->Paginator->sort('category_id'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<?php foreach ($products as $product): ?>
<tbody>
<tr>
<td><?php echo h($product['Product']['name']); ?> </td>
<td><?php echo h($product['Product']['product_code']); ?> </td>
<td><?php echo h($product['Product']['image_name']); ?> </td>
<td><?php echo h($product['Product']['image_url']); ?> </td>
<!--<td><?php echo h($product['Product']['brand_id']); ?> </td>
<td><?php echo h($product['Product']['reward_id']); ?> </td>-->
<td><?php echo h($product['Product']['product_status_id']); ?> </td>
<td><?php echo h($product['Product']['serial_id']); ?> </td>
<td><?php echo h($product['Product']['category_id']); ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $product['Product']['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $product['Product']['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $product['Product']['id']), null, __('Are you sure you want to delete # %s?', $product['Product']['id'])); ?>
</td>
</tr>
</tbody>
<?php endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<div class="paging">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('New Product'), array('action' => 'add')); ?></li>
</ul>
</div>
我猜您正在嘗試在CakePHP分頁中包含datatable.js。
datatable.js和CakePHP Paginator都是兩種不同的數據過濾方法。 Cake Paginator在服務器中執行所有類型的過濾,並且僅在表中顯示結果數據。 Datatable.js可在客戶端(javascript)中使用。
當在分頁表上應用datatable.js時,它將僅過濾結果數據,而不是整個數據。
您可以使用以下兩種方法中的任何一種
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.