为什么不是'我的datatables.js上的搜索函数正在工作
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分页器都是过滤数据的两种不同方法。CakePaginator在服务器中执行所有类型的过滤,并且只在表中显示结果数据。Datatable.js在客户端(javascript)中工作。
当您在分页表上应用datatable.js时,它将只过滤结果数据,而不是整个数据。
您可以使用以下2种方法中的任何一种
- 利用数据表服务器端处理(Matt Hughes在这里为CakePHP编写了一份很好的文档https://datatables.net/development/server-side/php_cake)
- 使用CakePHP数据表组件。(一个喜欢https://github.com/cnizzdotcom/cakephp-datatable)
相关文章:
- Javascript搜索函数错误
- 具有嵌套对象数组的 Javascript 对象的递归搜索函数
- 搜索函数未返回结果
- HTML/Javascript 搜索函数与 AJAX
- 尝试取消反弹搜索函数调用会导致不会将任何事件传递给函数
- 使用 jQuery 隐藏搜索函数中不匹配的选项
- jQuery 不与 JS 搜索函数一起使用
- 我的本地站点中的 JavaScript 搜索函数一直返回未定义
- JavaScript 中的搜索函数中出错
- 如何拦截 jQuery Datatables 搜索函数以在搜索之前重新加载数据(函数的名称是什么)
- javascript搜索函数在IE中不起作用
- 为什么不是'我的datatables.js上的搜索函数正在工作
- ajax搜索函数使用$(window).bind('hashchange',function(e)调用了
- 使用JavaScript在HTML中搜索函数
- 搜索函数javascript提交
- 如何使用MySQL和PHP创建一个通配符搜索函数
- 使用list.js(搜索函数)搜索HTML表-修改以显示所有不包括搜索词的行
- 如何用jquery创建搜索函数
- Javascript搜索函数read '*'和& # 39;强生# 39;是一样的
- 在表排序器搜索函数中只显示一个结果