【问题标题】:Cakephp ajax pagination for filters search resultsCakephp ajax 分页过滤器搜索结果
【发布时间】:2015-02-11 19:36:11
【问题描述】:

我正在使用 cakephp 2.4.5 并使用 ajax 进行过滤。我对哪些过滤数据和通过 ajax 分页获取结果进行了细化搜索。现在我要做的是,当我单击下一步时,它应该加载下一组结果在 div.Using cakephp paginator helper 它重定向到其他页面,如http://localhost/teacher/Joblistings/getdataviaajax/page:2

getdataviaajax 的 Controllrt 代码

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]

【问题讨论】:

  • 你能给你看代码吗...
  • [关闭] 尝试搜索 DataTables。它对您的需求很有趣,并且更容易实现它。 datatables.net
  • 我不输出表格格式
  • 但是在你的 HTML 代码中有一个表格。
  • 数据为ul li格式

标签: php ajax cakephp pagination


【解决方案1】:

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

  1. 获取所有列表
  2. 按长度分组创建新列表..

例如。根据页码,你得到了这样的列表。

  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];
   }

【讨论】:

    【解决方案2】:

    你有没有检查全局锚标记编码...

    它可能附加了attr target=_blnk,如果没有,则必须将layoput绑定到view ..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 2019-04-17
      • 2018-08-17
      相关资源
      最近更新 更多