Cakephp ajax 过滤搜索结果的分页
Cakephp ajax pagination for filters search results
我正在使用 cakephp 2.4.5 并为 filteration.I 使用 ajax 进行细化搜索以过滤数据并通过 ajax 和 pagination.Now 获取结果必须做的是,当我单击下一步时,它应该在 div.Using cakephp paginator helper 中加载下一组结果,它会重定向到其他页面,例如 http://localhost/teacher/Joblistings/getdataviaajax/page:2
getdatavia 的控制代码ajax
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]
你检查过全局锚标签编码了吗...
它可能附加了 attr target=_blnk,如果没有,那么您必须绑定 layoput 才能查看..
您可以创建自己的寻呼机而不是使用插件...
- 获取所有列表
- 按长度分组创建新列表..
例如。根据页码,您得到了这样的列表。
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];
}
我正在使用 cakephp 2.4.5 并为 filteration.I 使用 ajax 进行细化搜索以过滤数据并通过 ajax 和 pagination.Now 获取结果必须做的是,当我单击下一步时,它应该在 div.Using cakephp paginator helper 中加载下一组结果,它会重定向到其他页面,例如 http://localhost/teacher/Joblistings/getdataviaajax/page:2
getdatavia 的控制代码ajax
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]
你检查过全局锚标签编码了吗...
它可能附加了 attr target=_blnk,如果没有,那么您必须绑定 layoput 才能查看..
您可以创建自己的寻呼机而不是使用插件...
- 获取所有列表
- 按长度分组创建新列表..
例如。根据页码,您得到了这样的列表。
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];
}