efilterwidget / README.md

EFilterWidget

author: Christian Salazar christiansalazarh@gmail.com

licence: NEW BSD

screenshot

Wiki en Español:

http://yiiframeworkenespanol.org/wiki/index.php?title=EFilterWidget

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'));
}
?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.