【发布时间】:2014-09-30 04:43:41
【问题描述】:
我正在开发一个具有下拉菜单过滤器的搜索表单。该网站是由 Yii 创建的。
我的过滤器表单在提交之前是这样的:PIC 1
选择过滤器时的表单:PIC 2
但当我点击filter 按钮后,它又会像这样:PIC3
但我希望在提交表单后显示结果时表单应保持为PIC 2。
我的表格是:
<div class="row">
<div style="float: left">
<label class="form_controller required">By Brand</label>
<select style="width: 148px;" id="select_options" name="SCDcustomer_contacts_cms[brand_select_option]">
<option value="none">Select an option</option>
<option value="brand_preference">Brand Preference</option>
<option value="brand_purchased">Brand Purchased</option>
</select>
</div>
<div id="select_a_brand" name="select_a_brand">
<?php echo $form->dropDownList($model,'brand_id', gGetBrandList('brand_id', 'brand_id, brand_name'), array('prompt'=>'Select a brand')); ?>
</div>
<script type="text/javascript">
$(document).ready(function(){
jQuery('#select_a_brand').hide();
$("#select_options").change(function(){
$( "select option:selected").each(function(){
if(($(this).attr("value")=="brand_preference") || ($(this).attr("value")=="brand_purchased") ){
$("#select_a_brand").show();
}
if($(this).attr("value")=="none"){
$("#select_a_brand").hide();
}
});
});
});
</script>
</div>
规则函数是:
public function rules()
{
return array(
array('scd_cust_id,cust_id,order_first_name,order_surname,order_email,order_postcode, brand_id, brand_select_option', 'safe', 'on'=>'search'),
);
}
表单过滤器是:
if(!empty($filter)) {
if ($this->brand_select_option == "brand_preference") {
$criteria->select .= ', COUNT(*) as brand_preference';
$criteria->join .= ' INNER JOIN order_table ot ON ot.billing_contactid = t.contactid';
$criteria->join .= ' INNER JOIN order_item oi ON ot.scd_order_id = oi.scd_order_id';
$criteria->join .= ' INNER JOIN johnanthony_rstest.product p ON p.product_id = oi.product_id';
$criteria->condition .= (!empty($criteria->condition) ? ' AND ' : '') . 'p.brand_id=:brand_id';
$criteria->group = 't.contactid';
$criteria->order = 'COUNT(*) DESC';
$criteria->params = array(':brand_id'=>$this->brand_id);
$paging['pagination']['route']='report/index?SCDcustomer_contacts_cms[brand_id]=' . $this->brand_id;//For ajax pagination URL
}
if ($this->brand_select_option == "brand_purchased") {
$criteria->select .= ', SUM(product_price) AS brand_purchased';
$criteria->join .= ' INNER JOIN order_table ot ON ot.billing_contactid = t.contactid';
$criteria->join .= ' INNER JOIN order_item oi ON ot.scd_order_id = oi.scd_order_id';
$criteria->join .= ' INNER JOIN johnanthony_rstest.product p ON p.product_id = oi.product_id';
$criteria->condition .= (!empty($criteria->condition) ? ' AND ' : '') . 'p.brand_id=:brand_id';
$criteria->group = 't.contactid';
$criteria->order = 'SUM(product_price) DESC';
$criteria->params = array(':brand_id'=>$this->brand_id);
$paging['pagination']['route']='report/index?SCDcustomer_contacts_cms[brand_id]=' . $this->brand_id;//For ajax pagination URL
}
}
Ajax 文件是:
if (!empty($model->brand_id) && ($model->brand_select_option == "brand_preference")) {
array_push($options['columns'], array(
'name'=>'brand_preference',
'filter'=>false,
'header'=>'Brand Preference (No of purchased items)',
'type'=>'raw',
'value'=>'$data->brand_preference',
));
}
if (!empty($model->brand_id) && ($model->brand_select_option == "brand_purchased")) {
array_push($options['columns'], array(
'name'=>'brand_purchased',
'filter'=>false,
'header'=>'Brand Purchased (Sum of purchased items)',
'type'=>'raw',
'value'=>'$data->brand_purchased',
));
}
【问题讨论】:
标签: javascript php forms yii