Cakephp ajax分页筛选搜索结果

时间:2015-02-11 10:36:29

标签: php ajax cakephp pagination

我正在使用cakephp 2.4.5并使用ajax进行过滤。我有一个精炼搜索过滤器数据和通过ajax与pagination获取结果。现在我要做的是当我点击下一步它应该加载下一组div中的结果。使用cakephp paginator helper重定向到其他页面,如http://localhost/teacher/Joblistings/getdataviaajax/page:2

getdataviaajax的控制代码

public function getdataviaajax(){
        $this->Paginator->settings = $this->paginate;
        $this->layout=false;
        if($this->request->is('ajax')){
            $conditions = array();
        if(!empty($this->request->data['cityid'])){
            $conditions['Joblisting.location_id'] = $this->request->data['cityid'];
        }
        if(!empty($this->request->data['jobid'])){
            $conditions['Joblisting.jobcategory_id']= $this->request->data['jobid'];
        }
        if(!empty($this->request->data['jobid'])){
            $conditions['Joblisting.jobcategory_id'] = $this->request->data['jobid'];   
        }
        if(!empty($this->request->data['experienceid'])){
            $conditions['Joblisting.experiencefrom'] = $this->request->data['experienceid'];
        }
        if(!empty($this->request->data['salaryid'])){
            $conditions['Joblisting.salaryfrom'] = $this->request->data['salaryid'];
        }
        $searchresults = $this->paginate('Joblisting',array($conditions));
        $this->set(compact('searchresults'));
        }else{
            $searchresults=array();
            $this->set(compact('searchresults'));
        }

    }

和searchresults.ctp获取结果

<div class="col-md-3">
            <div class="table-responsive" style="background-color: #F5F5F5;">
                            <table class="table table-hover course-list-table tablesorter">
                                <thead>
                                <tr>
                                    <th>Refine Searches</th>
                                </tr>
                                </thead>
                                <tbody class="tbodyth">
                                <tr>
                                <th class="course-title">
                                    <?php echo $this->Form->input('city_id',array('label'=>false,'empty'=>'--Select City--','class'=>'selcalss','type'=>'select','style'=>'text-transform:capitalize;','id'=>'cityid'));?>
                                </th>

                                </tr>
                                 <tr>
                                <th class="course-title">
                                    <?php echo $this->Form->input('jobcategory_id',array('label'=>false,'empty'=>'--Select Institute--','class'=>'selcalss','id'=>'jobcatid'));?>
                                </th>
                                </tr>

                                 <tr>
                                <th class="course-title">
                                    <?php echo $this->Form->input('skill_id',array('label'=>false,'empty'=>'--Select Skills--','class'=>'selcalss','id'=>'skillid'));?>
                                </th>
                                </tr>

                                <tr>
                                <th class="course-title">
                                    <?php echo $this->Form->input('experience',array('id'=>'experience','label'=>false,'empty'=>'--Select Experience--','class'=>'selcalss','type'=>'select','options'=>$this->Common->experiencelist()));?>
                                </th>
                                </tr>
                                <tr>
                                <th class="course-title">
                                    <?php echo $this->Form->input('salary',array('id'=>'salaries','label'=>false,'empty'=>'--Expected Salary in Lakhs--','class'=>'selcalss','type'=>'select','options'=>$this->Common->salaries()));?>
                                </th>
                                </tr>

                                <tr>
                                <th class="course-title">
                                    <?php echo $this->Form->input('Search',array('id'=>'button','type'=>'button','label'=>false,'class'=>'btn btn-small pull-right'));?>
                                </th>
                                </tr>


                                </tbody>
                            </table>
                        </div>
         </div>
         <script>
            $(document).ready(function(){

                $('#button').click(function(){
                    $('#fadeid').addClass('fadebackgroundcolor');
                    $('.fadeimgclass').css('display','block');
                    var get_city_id = $('#cityid').val();
                    var get_job_id = $('#jobcatid').val();
                    var get_experience_id = $('#experience').val();
                    var get_salaries_id = $('#salaries').val();

                $.post(
                      '<?php echo Router::url('/Joblistings/getdataviaajax')?>',
                       {cityid: get_city_id,jobid:get_job_id,experienceid:get_experience_id,salaryid:get_salaries_id},
                       function(data){
                            $('#searchresultdata').html(data);
                            $('#fadeid').removeClass('fadebackgroundcolor');
                            $('.fadeimgclass').css('display','none');
                       }
                );
                });

                $('#jobcatid').change(function(){
                var jobcatid = $('#jobcatid').val();
                var url ='<?php echo Router::url('/Skills/getlists/')?>'+$('#jobcatid').val(); 
                $.getJSON(
                    url,   
                    function(data){  
                            $.each(data, function(ind, val){
                                $('#skillid').append('<option value='+val.Skill.skillname +'>'+val.Skill.skillname +'</option>');
                        }); 
                    }
                )

            })
            })
         </script>

数据从文件中重新载入

<?php 
if(sizeof($searchresults)==0){
    echo 'No Job Found Matching';
}
foreach($searchresults as $searches){ ?>
                            <li class="author-block" style="box-shadow: 0px 0px 2px 3px #cfcfcf">
                                <article class="paragraph-wrapper">
                                    <div class="inner">
                                        <header><h5><?php echo $searches['Joblisting']['jobheadline']?></h5></header>
                                        <p>
                                        <b><?php echo $searches['Joblisting']['experiencefrom']?>-<?php echo $searches['Joblisting']['experienceto']?> yrs </b>
                                           <span style="text-transform: capitalize"><?php echo $searches['Location']['cityname']?></span>
                                        </p>
                                        <p>
                                        <b>Keyskills : </b>
                                           Learning, L&D, Training & Development, T&D, Corporate Training...
                                        </p>
                                        <p>
                                        <b>Job Description:</b>
                                        <?php echo $searches['Joblisting']['jobdescription']?>
                                           To head L&D Department To identify training needs To get training modules designed ...
                                        </p>
                                    </div>
                                    <div style="padding: 10px; background-color: rgb(249, 249, 249);">
                                                <p>
                                        <img style="width: 8px;" src="<?php echo Router::url('/img/rssymbol.png') ?>">
                                                    <?php echo $searches['Joblisting']['salaryfrom'];?> To 
                                        <img style="width: 8px;" src="<?php echo Router::url('/img/rssymbol.png') ?>">  

<?php echo $searches['Joblisting']['salaryto']; ?>
<a href="<?php echo Router::url('/Purchasedmasters/detailinpurchasemaster/').$searches['Joblisting']['id']?>" class="btn btn-small pull-right">Pay Now</a>
                                        </p>
                                    </div>
                                </article>
                            </li>
                        <?php } ?>  
                        <div class="paging">
    <?php echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));?>
    <?php echo $this->Paginator->numbers(array('separator' => ''));?>
    <?php echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));?>
    </div>
        ![enter image description here][1]

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以创建自己的寻呼机,而不是使用插件......

  1. 获取所有列表
  2. 通过将其分组为长度来制作新列表..
  3. 实施例。你有这样的清单,按照页面编号

      YourAction(PageNo)
      {
         OldList = {a, b, c, d, e, f, g, h, i, j, k} // It may be outcome of some search result
         PageLength = 2;
         newList = {{a,b},{c,d},{e,f},{g,h},{i,j},{k,''}};
         Return newList[PageNo];
       }
    

答案 1 :(得分:0)

您是否检查了全局锚标记编码...

它可能附加attr target = _blnk,如果没有,那么你必须绑定layoput来查看..