Yii Framework Forum: Please Help Me Create A Widget To Datacolumn Of Gridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Please Help Me Create A Widget To Datacolumn Of Gridview Rate Topic: -----

#1 User is offline   Trần Minh Quang 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 13-December 12
  • Location:Tan Phu district, Dong Nai province, Viet Nam

Posted 18 January 2013 - 06:29 AM

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!
Code is poetry
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 18 January 2013 - 02:55 PM

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.
0

#3 User is offline   Trần Minh Quang 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 13-December 12
  • Location:Tan Phu district, Dong Nai province, Viet Nam

Posted 21 January 2013 - 12:37 AM

View Postseenivasan, on 18 January 2013 - 02:55 PM, said:

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. ^_^
Code is poetry
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 21 January 2013 - 06:31 AM

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.
0

#5 User is offline   Trần Minh Quang 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 13-December 12
  • Location:Tan Phu district, Dong Nai province, Viet Nam

Posted 21 January 2013 - 11:30 PM

Dear Friend

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

Regards.
Code is poetry
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users