EFilterWidget ============= author: Christian Salazar <> licence: NEW BSD ![screenshot]( "EFilterWidget Screenshot") Wiki en EspaƱol: EN -- This widget presents a form containing a set of fields defined on the widget arguments, when user press the 'Find' button an ajax action will be fired, in response the client must select an option obtained from your remote query. ES -- Este widget presenta un formulario al cliente, el cual dispara una consulta ajax con los parametros configurados, devolviendo al cliente una lista de opciones para seleccionar cuando este presiona el boton "Buscar"(Find). Example Widget: --------------- ~~~ <?php $this->widget('ext.efilterwidget.EFilterWidget' ,array( 'id'=>'efilterwidget1', 'findButtonLabel'=>'Find>>', 'okButtonLabel'=>'OK', 'fields'=>array( 'year'=>array( 'ui'=>'text', 'label'=>'Year:', 'value'=>'', 'size'=>10, ), 'month'=>array( 'ui'=>'list', 'label'=>'Months:', 'value'=>'FEB', 'size'=>10, 'options'=>array(''=>'??','JAN'=>'Enero','FEB'=>'Febrero'), ), ), // use this attribute to pass any data readed from your Form. // suppose you have $form->textField($model,'anyattribute'); // containing a value to be passed back to your action in order // to perform a search. // // in your action this value is passed via 'arg' attribute name // $_GET['arg'] // 'actionInputArgumentID'=>'Form_anyattribute', 'action'=>array('site/efilterwidgetsample'), 'receptorId'=>'testValue', 'onSuccess'=>"function(data){ $('#logger').html(data); }", 'onError'=>"function(err){ $('#logger').html('error: '+err); }", 'backgroundColor'=>'#ccffee', )); ?> <div id='logger'></div> <?php echo "Example text field receptor:"; echo CHtml::textField('testValue',''); ?> ~~~ Your Action: ------------ ~~~ <?php // in any controller, please be consistent with 'action' parameter on widget. // public function actionEFilterWidgetSample(){ // 'keys' is an argument sent by EFilterWidget who informs about // each key present in URL argument. is a helper. // is a comma-separated key names string. $keys = explode(",",$_GET['keys']); // a value readed from your form referenced by: 'actionInputArgumentID' $anyValue = $_GET['arg']; // sample array filtered by argument passed by URL // example: // Person::model()->findByAttributes(array('uid'=>$_GET['uid'])); // available keys: $_GET['keys'], will return: "uid,firstname" (ie). $sample = array( array('userid'=>'U1', 'name'=>'christian') ,array('userid'=>'U2', 'name'=>'anahi') ,array('userid'=>'U3', 'name'=>'pedro') ,array('userid'=>'U4', 'name'=>'lisbeth') ); // IMPORTANT: // The widget requires JSON data // please return a value generated by CHtml::listData // and converted to json using: CJSON::encode(...) header("Content-type: application/json"); echo CJSON::encode(CHtml::listData($sample, 'userid', 'name')); } ?> ~~~