i have a grid with filter
i want add custom filter field, outside the grid
how can i do it?
the problem =if i use grid filter, it don’t include outside filter field
i have a grid with filter
i want add custom filter field, outside the grid
how can i do it?
the problem =if i use grid filter, it don’t include outside filter field
You can use a form like the ‘advanced search’ on the crud admin page:
Yii::app()->clientScript->registerScript('search', "
$('#search-form form').submit(function(){
$.fn.yiiGridView.update('your-grid-id', {
data: $(this).serialize()
});
return false;
});
");
?>
<div id="search-form" class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row">
<?php echo $form->label($model,'attribute'); ?>
<?php echo $form->textField($model,'attribute',array('size'=>20,'maxlength'=>20)); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!--form-->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'your-grid-id',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
....
it’s not the same
if i add different field (field than not in grid )to this search form, then make search and then filter in grid, it will resed my custom field value
this form only fill grid filter fields
I see what you mean now. I have a page that does this and I didn’t even realize this issue!
Well, now we both have this problem! Awesome.
EDIT:
Ok friend, I found a workaround for our now-shared issue. Add this to your beforeAjaxUpdate in the CGridView
<?php
'beforeAjaxUpdate'=>'js:function(id,options){
var fields = $(\'#search-form form\').serializeArray();
$.each(fields, function(i, field){
if(field.name == "model[attribute1]" || field.name == "model[attribute2]")
options.url = options.url+"&" + encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value);
});
}',
?>
thanks, but as for me it’s not beautiful solution
may be there is another solution, when cgridview automatic use custom filter fields, outside the grid?
Does it not work, or is it just not your style?
If you’re using ajax to update, you’re going to have to use some kind of javascript function, or extend CGridView somehow.
Here’s an option without a loop:
<?php
'beforeAjaxUpdate'=>'js:function(id,options){
var fields = "&" + encodeURIComponent("model[attribute]") +
"=" + encodeURIComponent($(\'#search-form #model_attribute\').val());
options.url = options.url+fields;
});
}',
?>
or
'beforeAjaxUpdate' => 'js:function(id, options) {
options.url = options.url + "&" + $(".search-form form").serialize();
}',
?
thanks, this is more good solution
so i see there is no standart yii solution to use custom filter fiels
all thanks