Please Help Me Create A Widget To Datacolumn Of Gridview

My code:


array(

        'name'=>'userId',

        'value'=>'Controller::createWidget("zii.widgets.jui.CJuiAutoComplete",array(

          "model"=>$data,

          "attribute"=>"userId",

          "sourceUrl"=>"",

        ))->run()',

      ),

But when running is have error:


Error 500: <h1>PHP Error [2048]</h1>

<p>Non-static method CBaseController::createWidget() should not be called statically, assuming $this from incompatible context (C:\wamp\www\prolab\framework\base\CComponent.php(607) : eval()'d code:1)</p>

Please help me!

Dear Friend

Please Try the following.




array(

        'name'=>'userId',

        'value'=>'$this->grid->controller->createWidget("zii.widgets.jui.CJuiAutoComplete",array(

          "model"=>$data,

          "attribute"=>"userId",

          "source"=>array("foo","bar","baz"),

        ))->run()',

      ),



There are two things will happen.

1.Hidden field is also displayed in the cell.

2.Default values in database is being displayed.

If you get any success in eliminating them, kindly give your response.

Regards.

I realy thank you very much. it show 2 values for me: (I use typeahead)

  1. emty field is display if don’t have values in database

  2. and default values is display if have value in database.

==> If want to display only emty field:


array(

        'name'=>'userId',

        'value'=>'$this->grid->controller->createWidget("bootstrap.widgets.TbTypeahead",array(

          "name"=>"User[userId]",

          "source"=>array("foo","bar","baz"),

        ))->run()',

      ),

But when update gridview, Widget is not run again. I try add ‘afterAjaxUpdate’ for gridview but it not run


'afterAjaxUpdate'=>'function(id, data){$(".typeAhead").typeahead();}'

You have any solution for me, please help me.

Thanks you!

Sorry you because my english is bad. ^_^

Dear Friend

The following would clear all the problems we are facing.

Create a column like this.We are not using any attribute name.We are just creating an input which has html attribute username which is unique for each field.




array(

    'value'=>'$this->grid->controller->createWidget("zii.widgets.jui.CJuiAutoComplete",array(

		 "id"=>$data->id,

                 "name"=>"username[".$data->id."]",

                ))->run()',

),



The line


"name"=>"username[".$data->id."]"

would be helpful in collecting data if we are treating the grid as form.

Now register below the grid the following script.

It ensures two things.

1.Auto complete is available even after a AJAX calls.

2.It also generates the source.

I am getting all the usernames from table user.




Yii::app()->clientScript->registerScript('test','

$("body").on("focus","#section-grid input",function(){   

    $(this).autocomplete({                           

        source:'.CJavaScript::encode(array_values(CHtml::listData(User::model()->findAll(),"id","name"))).'

                        })

            });

');



section-grid is the id of my CGridView.

Be careful with single and double quotes.

Regards.

Dear Friend

I realy, realy, realy thanks you very much about your help. it’s perfect for me. once again thanks you.

Regards.