我有一个表格,我希望使用分页,我的表数据由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
我的Cntroller
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);
}
}
答案 0 :(得分:4)
在视图文件的顶部添加此行。
$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
您可以获得更多信息here。