我正在搜索表單上有一個下拉菜單過濾器。該網站由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
}
}
阿賈克斯文件:
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',
));
}
謝謝你。這應該是解決方案。但我不能只是複製過去並開始工作。我收到一個錯誤。我把這樣的代碼放在我的表單中,而不是按鈕:http://tinypic.com/r/2rfzy2d/8 ,我得到這個錯誤:' 解析錯誤:語法錯誤,意外的T_CONSTANT_ENCAPSED_STRING,期待')'在線86上的/var/www/vhosts/rstest.john-anthony.com/httpdocs/protected/modules/admincms/views/report/index.php' – 2014-09-30 06:43:42
這將不起作用,如示例中所示。首先,我懷疑你有div或任何其他的HTML標籤與ID#search-result-holder(這應該是你的HTML結果的地方)。鑑於你應該通過renderPartial('report/extra-views-folder/search-result',array('model'=> $ model),true)返回在控制器或其他視圖中生成的html數據。 CJSON :: encode(array('search-results'=> $ assigned_to_renderPartial_variable));當然,您必須將brand_id(SCDcustomer_contacts_cms [brand_id])傳遞給屬性。 – juslintek 2014-09-30 07:41:50
我的視圖文件(httpdocs \ protected \ modules \ admincms \ views \ report \ index.php)的結尾是這樣的:http://tinypic.com/r/dqgk1d/8 和我的ajax文件(httpdocs \ protected \ modules \ admincms \ views \ report \ _ajaxContent.php)是:http://www.ldjf.org/_ajaxContent.zip查看第50行 – 2014-09-30 07:59:08