我有一个表,我想在其中使用分页,我的表数据由Ajax填充。
这是我使用的表格:
<div class="portlet box green Report index">
<div class="portlet-title">
<div class="caption"><i class="icon-globe"></i>Report Summary</div>
<div class="tools">
<a href="javascript:;" class="collapse"></a>
</div>
</div>
<div class="portlet-body">
<div id="content">
<table class="table table-striped table-bordered table-hover table-full-width" id="sample_1">
<thead>
<tr id='content2'>
<?php //echo $content_for_layout; ?>
<th><?php echo $this->Paginator->sort('name); ?></th>
<th><?php echo $this->Paginator->sort('clicks); ?></th>
<th><?php echo $this->Paginator->sort('conversions'); ?></th>
<th><?php echo $this->Paginator->sort('payout'); ?></th>
<th><?php echo $this->Paginator->sort('ltr'); ?></th>
<th><?php echo $this->Paginator->sort('cpc'); ?></th>
</tr>
</thead>
<tbody class="report_data">
</tbody>
</table>
</div>
</div>
</div>
在我的观点之上,我有以下内容:
$this->Paginator->options(array(
'update' => '#content2',
'evalScripts' => true,
));
在我的控制器中,我记得有以下助手和组件:
public $components = array('RequestHandler');
public $helpers = array('Js' => array('Jquery'), 'Paginator');
在我的观点的最后,我补充道:
<?php echo $this->Js->writeBuffer(); ?>
现在,每当我点击其中一个表链接,网站就会重新加载,但有两个主要问题:
发送回分页器的数据既不包含排序也不包含顺序(也就是说,站点基本上只是重新加载)
网站的渲染混乱(这是一个小问题,但仍然非常烦人)
有人能告诉我我做错了什么吗?
蛋糕版本2.3
我的控制器
class ReportsController extends AppController
{
public $name = 'Reports';
public $components = array( 'BloglicHelper', 'RequestHandler', 'HasOffers');
public $helpers = array('Js' => array('Jquery'), 'Paginator');
public $paginate = array(
'fields' => array(
'Stat.clicks'
,'Offer.name'
,'Stat.currency'
,'Stat.conversions'
,'Stat.payout'
,'Stat.ltr'
,'Stat.cpc'
,'Stat.affiliate_id')
,'conditions' => array( 'Stat.affiliate_id' => array(
'conditional' => "EQUAL_TO",
'values' => array(1002)
)
, 'Stat.date' => array(
'conditional' => 'BETWEEN'
, 'values' => array(
)
),
),
'group' =>array('Offer.name'),
'Method' => 'getStats',
'totals' => true
);
public function index(){
$this->layout = 'client_layout';
}
public function ajax_index(){
if ($this->RequestHandler->isAjax())
{
$this->autoLayout = false;
$this->autoRender = false;
$this->layout = 'ajax';
}
//request selected dates
$startDate = $this->request->data['startDateTime'];
$endDate = $this->request->data['endDateTime'];
array_push($this->paginate['conditions']['Stat.date']['values'], $startDate, $endDate);
;
$finalData = array( 'table' => $this->paginate());
print json_encode($finalData);
}
}
在视图文件的顶部添加此行。
$this->Paginator->options(array(
'update' => '#content',
'evalScripts' => true,
));
在这里,您必须更新整个表,而不是仅更新一行,即#content2
<div class="portlet box green Report index">
<div class="portlet-title">
<div class="caption"><i class="icon-globe"></i>Report Summary</div>
<div class="tools">
<a href="javascript:;" class="collapse"></a>
</div>
</div>
<div class="portlet-body">
<div id="content">
<table class="table table-striped table-bordered table-hover table-full-width" id="sample_1">
<thead>
<tr id='content2'>
<?php //echo $content_for_layout; ?>
<th><?php echo $this->Paginator->sort('name'); ?></th>
<th><?php echo $this->Paginator->sort('clicks'); ?></th>
<th><?php echo $this->Paginator->sort('conversions'); ?></th>
<th><?php echo $this->Paginator->sort('payout'); ?></th>
<th><?php echo $this->Paginator->sort('ltr'); ?></th>
<th><?php echo $this->Paginator->sort('cpc'); ?></th>
</tr>
</thead>
<tbody class="report_data">
</tbody>
</table>
<ul>
<?php if ($this->Paginator->hasPrev()): ?>
<li><?php echo $this->Paginator->first(__('First')) ?></li>
<li><?php echo $this->Paginator->prev(__('Prev'), array(), null, array('class' => 'prev disabled')) ?></li>
<?php
endif;
echo $this->Paginator->numbers(array('currentTag' => 'span', 'currentClass' => 'active',
'separator' => false, 'tag' => 'li', 'modulus' => 5));
if ($this->Paginator->hasNext()):
?>
<li><?php echo $this->Paginator->next(__('Next'), array(), null, array('class' => 'next disabled')) ?></li>
<li><?php echo $this->Paginator->last(__('Last')) ?></li>
<?php endif ?>
</ul>
<?php echo $this->Js->writeBuffer(); ?>
</div>
</div>
</div>
中有一些错误
<th><?php echo $this->Paginator->sort('name); ?></th>
<th><?php echo $this->Paginator->sort('clicks); ?></th>
这两条线
<?php echo $this->Js->writeBuffer(); ?>
应该位于要更新的元素内部。即此处为#content
你可以在这里获得更多信息。