2015-02-11 96 views
0

我正在使用cakephp 2.4.5和使用ajax filteration.I有一個精煉的搜索,哪些過濾器的數據和通過ajax與分頁獲取結果。現在我要做的是當我點擊接下來,它應該加載下一組重定向到其他頁面的div.Using CakePHP的分頁程序助手裏的結果,像http://localhost/teacher/Joblistings/getdataviaajax/page:2Cakephp ajax分頁過濾器搜索結果

Controllrt代碼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> 

的數據從文件reloded爲

<?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

+0

你能告訴你代碼嗎... – 2015-02-11 10:37:52

+0

[關]嘗試搜索DataTables。它對你的需求很有意思,並且更容易實現。 datatables.net – bcesars 2015-02-11 10:55:57

+0

我不輸出表格格式 – Asim 2015-02-11 11:06:02

回答

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

你有檢查的全球定位標記編碼...

可能使用attr目標= _blnk進行追加,如果沒有的話你必須綁定layoput查看..