所以经过很长一段时间后,很多麻烦我终于让我的ajax分页工作了(有点像)
现在我的html看起来像这样:
<?php
$this->Paginator->options(array(
'update' => '#content',
'evalScripts' => true,
));
?>
<div class="portlet box green Report index" id="content">
<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">
<table class="table table-striped table-bordered table-hover table-full-width"
<thead>
<tr>
<th><?php echo $this->Paginator->sort('Offer.name','Offer'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.clicks','Clicks'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.conversions','Conversion'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.payout','Payout'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.ltr', 'What-isThis?'); ?></th>
<th><?php echo $this->Paginator->sort('Stat.cpc','Expected E-CPC'); ?></th>
</tr>
</thead>
<tbody class="report_data">
<?php foreach ($table['Report']['data']['data'] as $res): ?>
<tr>
<td><?php echo h($res['Offer']['name']); ?> </td>
<td><?php echo h($res['Stat']['clicks']); ?> </td>
<td><?php echo h($res['Stat']['conversions']); ?> </td>
<td><?php echo h($res['Stat']['payout']); ?> </td>
<td><?php echo h($res['Stat']['ltr']); ?> </td>
<td><?php echo h($res['Stat']['cpc']); ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
<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 ?>
</table>
</ul>
</div>
</div>
</div>
<?php echo $this->Js->writeBuffer(); ?>
很遗憾,我无法向你展示一张图片(它说我缺乏声誉),但似乎当我按下分页时,它会将网站的内容放入div块中,这意味着该视图会被搞砸了!
任何人都可以告诉我为什么这样做以及我如何解决它?
我尝试将id ='content'移动到不同的div或table块但没有成功
蛋糕版2.3
我的索引操作
public function index()
{
if($this->request->is('ajax'))
{
$this->layout('ajax');
}else{
$this->layout = 'client_layout';
}
$startDate = $this->request->data['startDateTime'];
$endDate = $this->request->data['endDateTime'];
if($startDate == null || $startDate == '' ){
$startDate = date('y-m-d');
$endDate = date('y-m-d');
}
array_push($this->paginate['conditions']['Stat.date']['values'], $startDate, $endDate);
$this->set('table', $this->paginate());
}
更新
好的,所以在我的控制器中我添加了以下内容:
if ($this->RequestHandler->isAjax()) {
$this->autoLayout = true;
$this->autoRender = true;
$this->layout = 'ajax';
}else{
$this->layout = 'client_layout';
}
现在这有助于它不应该是100%,现在它是在表格顶部添加一个div块,这里有一些HTML的样子:
<div id="updateTable">
<div class="portlet box red"> <-- VERY BAD!!
<div class="portlet-title">
<div class="portlet-body">
</div>
<div id="updateTable">
请注意我也将ID更改为updateTable
答案 0 :(得分:0)
在您的控制器操作中,分页链接正在检查请求是否在ajax中。如果通过ajax发出请求,则告诉控制器不要添加头和其他css代码。
if($this->request->is('ajax'))
{
$this->layout('ajax');
}
答案 1 :(得分:0)
您的HTML标记无效。 table-element关闭得太晚,只需移动
</table>
之前
<ul>
并删除最后一个div-tag。
据我所知,您不必手动检查ajax请求。如果组件中包含RequestHandler,则应自动选择相应的布局。
只需将以下内容添加到AppController:
public $components = array('RequestHandler');