1

我有一个表,我想在其中使用分页,我的表数据由 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(); ?>

现在,每当我单击其中一个表格链接时,网站都会重新加载,但有两个主要问题:

  1. 发送回分页器的数据不包含排序或顺序(也就是网站基本上只是重新加载)

  2. 该网站的渲染搞砸了(这是一个小问题,但仍然很烦人)

谁能告诉我我做错了什么?

蛋糕 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);

    }

}
4

1 回答 1

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

你可以在这里获得更多信息。

于 2013-09-03T14:39:15.593 回答