[Extension] Efillablecgridview

Hello,

I just open this thread as a support for eFillableCGridView extension.

Feel free to report any bug or evolution.

Regards

I get the error when i tried to implement the extension


Object of class Patinfo could not be converted to string


C:\wamp\www\installyii\framework\web\helpers\CHtml.php(1918)


1906             return call_user_func($attribute,$model);

1907 

1908         return $model;

1909     }

1910 

1911     /**

1912      * Generates a valid HTML ID based on name.

1913      * @param string $name name from which to generate HTML ID

1914      * @return string the ID generated based on name.

1915      */

1916     public static function getIdByName($name)

1917     {

1918         return str_replace(array('[]', '][', '[', ']', ' '), array('', '_', '_', '', '_'), $name);

1919     }

1920 

1921     /**

1922      * Generates input field ID for a model attribute.

1923      * @param CModel $model the data model

1924      * @param string $attribute the attribute

1925      * @return string the generated input field ID

1926      */

1927     public static function activeId($model,$attribute)

1928     {

1929         return self::getIdByName(self::activeName($model,$attribute));

1930     }

Stack Trace

#0	

+  C:\wamp\www\installyii\framework\web\helpers\CHtml.php(1918): str_replace(array("[]", "][", "[", "]", ...), array("", "_", "_", "", ...), Patinfo)

#1	

+  C:\wamp\www\installyii\framework\web\helpers\CHtml.php(1172): CHtml::getIdByName(Patinfo)

#2	

+  C:\wamp\www\installyii\framework\web\helpers\CHtml.php(580): CHtml::inputField("text", Patinfo, "sex", array())

#3	

–  C:\wamp\www\roopesh\protected\views\patinfo\admin.php(51): CHtml::textField(Patinfo, "sex")

46     // **** Here starts the addition ****

47    'fillable' => array(

48       'columns' => array(

49          array(

50             'name' => 'pid',

51             'value' => CHtml::textField($model,'sex')

52          ),

53          array(

54             'name' => 'age',

55             'value' => CHtml::textField($model,'age')

56          ),

#4	

+  C:\wamp\www\installyii\framework\web\CBaseController.php(126): require("C:\wamp\www\roopesh\protected\views\patinfo\admin.php")

#5	

+  C:\wamp\www\installyii\framework\web\CBaseController.php(95): CBaseController->renderInternal("C:\wamp\www\roopesh\protected\views\patinfo\admin.php", array("model" => Patinfo), true)

#6	

+  C:\wamp\www\installyii\framework\web\CController.php(869): CBaseController->renderFile("C:\wamp\www\roopesh\protected\views\patinfo\admin.php", array("model" => Patinfo), true)

#7	

+  C:\wamp\www\installyii\framework\web\CController.php(782): CController->renderPartial("admin", array("model" => Patinfo), true)

#8	

–  C:\wamp\www\roopesh\protected\controllers\PatinfoController.php(143): CController->render("admin", array("model" => Patinfo))

138         if(isset($_GET['Patinfo']))

139             $model->attributes=$_GET['Patinfo'];

140 

141         $this->render('admin',array(

142             'model'=>$model,

143         ));

144     }

145 

146     /**

147      * Returns the data model based on the primary key given in the GET variable.

148      * If the data model is not found, an HTTP exception will be raised.

#9	

+  C:\wamp\www\installyii\framework\web\actions\CInlineAction.php(49): PatinfoController->actionAdmin()

#10	

+  C:\wamp\www\installyii\framework\web\CController.php(308): CInlineAction->runWithParams(array("r" => "patinfo/admin"))

#11	

+  C:\wamp\www\installyii\framework\web\filters\CFilterChain.php(133): CController->runAction(CInlineAction)

#12	

+  C:\wamp\www\installyii\framework\web\filters\CFilter.php(40): CFilterChain->run()

#13	

+  C:\wamp\www\installyii\framework\web\CController.php(1145): CFilter->filter(CFilterChain)

#14	

+  C:\wamp\www\installyii\framework\web\filters\CInlineFilter.php(58): CController->filterAccessControl(CFilterChain)

#15	

+  C:\wamp\www\installyii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(CFilterChain)

#16	

+  C:\wamp\www\installyii\framework\web\CController.php(291): CFilterChain->run()

#17	

+  C:\wamp\www\installyii\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array("accessControl", "postOnly + delete"))

#18	

+  C:\wamp\www\installyii\framework\web\CWebApplication.php(282): CController->run("admin")

#19	

+  C:\wamp\www\installyii\framework\web\CWebApplication.php(141): CWebApplication->runController("patinfo/admin")

#20	

+  C:\wamp\www\installyii\framework\base\CApplication.php(169): CWebApplication->processRequest()

#21	

–  C:\wamp\www\roopesh\index.php(13): CApplication->run()

08 defined('YII_DEBUG') or define('YII_DEBUG',true);

09 // specify how many levels of call stack should be shown in each log message

10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

11 

12 require_once($yii);

13 Yii::createWebApplication($config)->run();

2013-08-06 00:04:30 Apache/2.2.22 (Win32) PHP/5.4.3 Yii Framework/1.1.13

My code


<?php $this->widget('application.extensions.EFillableCGridView', array(

	'id'=>'patinfo-grid',

	'dataProvider'=>$model->search(),

	// **** Here starts the addition ****

   'fillable' => array(

      'columns' => array(

         array(

            'name' => 'pid',

            'value' => CHtml::textField($model,'sex')

         ),

         array(

            'name' => 'age',

            'value' => CHtml::textField($model,'age')

         ),

         array(

            'name' => 'sex',

            'value' => CHtml::textField($model,'sex')

         ),

      ),

      'CButtonColumn' => array(

         'button' => '<a href="'.Yii::app()->createUrl('patinfo/create').'"><img style="vertical-align: middle;" src="'. Yii::app()->baseUrl .'/images/ico_plus.gif" alt="plus"></a>',

         'action' => Yii::app()->createUrl('patinfo/create'),

      ),

      'position' => 'bottom',

   ),

   // **** Here ends the addition ****

	'filter'=>$model,

	'columns'=>array(

		'id',

		'pid',

		'age',

		'sex',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>

It seems it’s the same trouble that Daniel encoutered after I did my correction.

Using CActiveForm and not CHtml in the view works for me, using as this:


$fillable = new CActiveForm();

$this->widget('application.extensions.EFillableCGridView', array(

   'id'=>'my-grid',

   'dataProvider'=>$model->search(),

   // **** Here starts the addition ****

   'fillable' => array(

      'columns' => array(

         array(

            'name' => 'MyCol1',

            'value' => $fillable->textField($model,'MyCol1')

         ),

         array(

            'name' => 'MyCol2',

            'value' => $fillable->textField($model,'MyCol2')

         ),

         array(

            'name' => 'MyCol3',

            'value' => $fillable->dropDownList($model, 'MyCol3', CHtml::listData(Col3::model()->findAll(), 'idCol3', 'nameCol3')),

         ),

      ),

      'CButtonColumn' => array(

         'button' => '<a href="'.Yii::app()->createUrl('control/createAjax').'"><img style="vertical-align: middle;" src="'. Yii::app()->baseUrl .'/images/ico_plus.gif" alt="plus"></a>',

         'action' => Yii::app()->createUrl('control/createAjax'),

      ),

      'position' => 'bottom',

   ),

   // **** Here ends the addition ****

   'filter'=>$model,

   'columns'=>array(

      'ColId',

      'MyCol1',

      'MyCol2',

      array(

         'name' => 'MyCol3',

         'value' => '$data->Col3->nameCol3',

      ),

      array(

         'class'=>'CButtonColumn',

      ),

   ),

));

I’ll find a way to make it better.

Crazycat,

Thank you for your reply

I have not yet tried the code … I will let you know if this works.

I also have one more question:

In the code below:


 Yii::app()->createUrl('control/createAjax'),

can i use :


 Yii::app()->createUrl('control/create'),

Is there a difference between the control/create and conrtol/createAjax

Can you please share the code for the controller for Ajax

Thank You

Hello,

There’s a difference, the actionCreate does a redirect if the creation is ok, and render the creation form if there are errors. the actionCreateAjax must echo simple text (or JSon string) wich can be used with the javascript, even if I actually don’t use this return.

Here are the two methods I’ve in my controller, you can see the differences:


/**

 * Creates a new model.

 * If creation is successful, the browser will be redirected to the 'view' page.

 */

public function actionCreate()

{

   $model=new MyModel;

   if(isset($_POST['MyModel']))

   {

      $model->attributes=$_POST['MyModel'];

      if($model->save())

         $this->redirect(array('view','id'=>$model->idMyModel));

   }

   $this->render('create',array(

      'model'=>$model,

   ));

}


/**

 * Creates a new model.

 * Echos a result and returns a boolean

 */

public function actionCreateAjax()

{

   $model=new MyModel;

   if(isset($_POST['MyModel']))

   {

      $model->attributes=$_POST['MyModel'];

      if($model->save())

         echo 'saved';

   }

   echo 'error';

   return true;

}

As you can see, the treatment is the same, it’s just the way we act after saving wich changes.

You can use the same action with an argument to know if you work in ajax or full page mode, but I prefer dissociated the two actions.

Hi Crazycat,

I changed the textbox you suggested and it works perfect!

Can i also do Ajax validation when i am creating a record?

Thanks

Filter not working I want to display Active for 1 and Inactive for 2 in status rows … I am not able to do so … here is my code


<?php $this->pageTitle=Yii::app()->name; ?>


<h1>Add Trial</h1>

<?php 

$dataprovider=new CActiveDataProvider('DRIPTTRIALHIS', array(

                        'criteria'=>array(

                                'condition'=>'PID=:id',

                                'params'=>array(':id'=>$_SESSION['patid']),

                        ),

                ));


$fillable = new CActiveForm();


$this->widget('application.extensions.EFillableCGridView', array(

	'id'=>'dripttrialhis-grid',

	'dataProvider'=>$dataprovider,

	//'filter'=>$model,

	 // **** Here starts the addition ****

   'fillable' => array(

      'columns' => array(

         array(

            'name' => 'PID',

            'value' => $fillable->textField($model,'PID',array('style' => 'text-align:center','value' => Yii::app()->session['patid'] ,'READONLY' =>'True','size'=>10,)),

			//'visible'=>True,

         ),

         array(

            'name' => 'TR_M_ID',

            'value' => $fillable->dropDownList($model,'TR_M_ID', CHtml::listData(DRIMSTRTRIAL::model()->findAll(), 'ID', 'IRB'), array('empty'=>'select Type'))

         ),

         array(

            'name' => 'CHNG_DT',

            'value' => $fillable->textField($model,'CHNG_DT',array('value'=>CTimestamp::formatDate('m-d-Y'),'READONLY'=>'True','size'=>10 ))

         ),

		   array(

            'name' => 'STATUS',

            'value' => $fillable->dropDownList($model,'STATUS',array('1'=>'Active', '2'=>'Inactive'))

         ),

		   array(

            'name' => 'COMMENT',

            'value' => $fillable->textField($model,'COMMENT',array('size'=>30))

         ),

      ),

      'CButtonColumn' => array(

         'button' => '<a href="'.Yii::app()->createUrl('DRIPTTRIALHIS/create').'"><img style="vertical-align: middle;" src="'. Yii::app()->baseUrl .'/images/ico_plus.gif" alt="plus"></a>',

         'action' => Yii::app()->createUrl('DRIPTTRIALHIS/create'),

      ),

      'position' => 'top',

   ),

   // **** Here ends the addition ****

	'columns'=>array(

		//'ID',

		 array(

          'name'=>'PID',

          //'visible'=>false

            ),

		//'PID',

		'TR_M_ID',

			 array(

                   'name'=>'CHNG_DT',

                   'value'=>'Yii::app()->dateFormatter->format("M-d-yyyy",$data->CHNG_DT)'

                ),

		//'CHNG_DT',

			array(

                  'name'=>'STATUS',

				  //'value'=> $this->STATUS == 1 ? "No" : "Yes",

				  'filter'=>array('1'=>'Active','2'=>'Inactive'),

                ),

		//'STATUS',

		'COMMENT',

		array(

			'class'=>'CButtonColumn',

					//'template'=>'{view}{update}{billing}{delete}',

					'buttons'=>array

					(

				'view' => array

					(

					'label'=>'view',

					//'imageUrl'=>Yii::app()->request->baseUrl.'/images/view.png',

					'url'=>'Yii::app()->createUrl("DRIPTCONSHIS/Add_Pt_Consent", array("id"=>$data->ID,"tid"=>$data->TR_M_ID))',

					),

				

				),

		),

	),

)); ?>




Hi,

I do apologise not yet put the code here since I have just come back from holiday.

It did worked after applied your suggestion.

One thing though, I had an impression of double html form in form of filter and the EFillable row. The thing is if I put some value on the filter, it will also shown on the EFillable row. I was thinking what if we just use the filter row? is it possible?

Mu client habit is to do searching on the cgridview for certain value, if the result is empty then, he will add it. That’s why I need a plus button next to the filter row so that, he can just search for the result, if empty he can just add the row in one simple click.

Cheers,

Daniel

Hello there, I’m just coming back from holiday.

@poorroop : I don’t think it’s the good way, you need to modify the value, not the filter.

@daniel : I understand what you mean, and it’s a good idea, I’ll work on it to have the option “filter mode”.

I am trying to add flash message when i create new record … I am not able to do it…

Can you please let me know what i am doing wrong?

here is my code


public function actionCreateAjax()

	{

		$model=new DRIORDERTESTS;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['DRIORDERTESTS']))

		{

			$model->attributes=$_POST['DRIORDERTESTS'];

			if($model->save())

				 Yii::app()->user->setFlash('feedback','Your feedback was received, it will be shown once it is approved.');

                $this->refresh();

		}


		echo 'error';

			return true;

		

	}


<?php $this->pageTitle=Yii::app()->name; ?>


<h1>Add Tests</h1>

<?php 

$dataprovider=new CActiveDataProvider('DRIORDERTESTS', array(

                        'criteria'=>array(

                                'condition'=>'PID=:id',

                                'params'=>array(':id'=>$_SESSION['patid']),

                        ),

                ));


$fillable = new CActiveForm();

$this->widget('application.extensions.EFillableCGridView', array(

	'id'=>'driordertests-grid',

	'dataProvider'=>$dataprovider,

	//'filter'=>$model,

	 // **** Here starts the addition ****

   'fillable' => array(

      'columns' => array(

         array(

            'name' => 'PID',

            'value' => $fillable->textField($model,'PID',array('style' => 'text-align:center','value' => Yii::app()->session['patid'] ,'READONLY' =>'True','size'=>10,)),

			//'visible'=>True,

         ),/*

         array(

            'name' => 'TR_M_ID',

            'value' => $fillable->dropDownList($model,'TR_M_ID', CHtml::listData(DRIMSTRTRIAL::model()->findAll(), 'ID', 'IRB'), array('empty'=>'select Type'))

         ),*/

         array(

            'name' => 'ORDER_DT',

            'value' => $fillable->textField($model,'ORDER_DT',array('value'=>CTimestamp::formatDate('m-d-Y'),'READONLY'=>'True','size'=>10 ))

         ),

		   array(

            'name' => 'TEST_M_ID',

            'value' => $fillable->dropDownList($model,'TEST_M_ID',array(1=>'Test 1', 2=>'Test 2'))

         ),

		   array(

            'name' => 'DONE_BY',

            'value' => $fillable->textField($model,'DONE_BY',array('size'=>30))

         ),

      ),

      'CButtonColumn' => array(

         'button' => '<a href="'.Yii::app()->createUrl('DRIORDERTESTS/createAjax').'"><img style="vertical-align: middle;" src="'. Yii::app()->baseUrl .'/images/ico_plus.gif" alt="plus"></a>',

         'action' => Yii::app()->createUrl('DRIORDERTESTS/createAjax'),

      ),

      'position' => 'top',

   ),

   // **** Here ends the addition ****

	'columns'=>array(

		'ID',

		'PID',

		'ORDER_DT',

		'TEST_M_ID',

		'DONE_BY',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>

<?php if (Yii::app()->user->hasFlash('feedback')):?>

    <div class="flash-success">

        <?php echo Yii::app()->user->getFlash('feedback');?>

    </div>

<?php endif;?>







Thanks

The trouble is that your flash message is in the main template, wich is not reloaded when you use the fill system.

I think you have to add an afterAjaxUpdate option in your grid (it’s a property from cgridview)

I have added


'afterAjaxUpdate' => 'js:function(id, data) {alert("You have added a new Record.");}',

it alerts for both error and sucess creation… is there a was to display message with condition?

This functionnality is now available, just download the new version of efillablecgridview and read about the fillIsFilter option.

Hi,

Will the relations work with fillable?




<?php

$this->breadcrumbs=array(

	'Drimstrtrials'=>array('index'),

	$model->ID=>array('view','id'=>$model->ID),

	'Update',

);


$this->menu=array(

	array('label'=>'List DRIMSTRTRIAL', 'url'=>array('index')),

	array('label'=>'Create DRIMSTRTRIAL', 'url'=>array('create')),

	array('label'=>'View DRIMSTRTRIAL', 'url'=>array('view', 'id'=>$model->ID)),

	array('label'=>'Manage DRIMSTRTRIAL', 'url'=>array('admin')),

);

?>




	

<h1>Update DRIMSTRTRIAL <?php echo $model->ID; ?></h1>


<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>

<?php 

$dataprovider=new CActiveDataProvider('dRIMSTRTRIALGRIDTEST', array(

                        'criteria'=>array(

                                'condition'=>'MSTR_TRIAL_ID=:id',

                                'params'=>array(':id'=>$model->ID),

                        ),

                ));


$fillable = new CActiveForm();

$model2=new DRIMSTRTRIALGRIDTEST;




$this->widget('application.extensions.EFillableCGridView', array(

	'id'=>'dripttrialhis-grid',

	'dataProvider'=>$dataprovider,

	//'filter'=>$model,

	 // **** Here starts the addition ****

   'fillable' => array(

      'columns' => array(

         array(

            'name' => 'MSTR_TRIAL_ID',

             'value' => $fillable->textField($model2,'MSTR_TRIAL_ID',array('style' => 'text-align:left','value' => $model->ID ,'READONLY' =>'True','size'=>10,)),

			//'visible'=>false,

         ),

		 array(

            'name' => 'TEST_ID',

		

			//'value' => $fillable->dropDownList($model2,'TEST_ID',array('1'=>'CBC', '2'=>'Chemistry', '3'=>'Lipids','4'=>'HbA1c', '5'=>'MMTI', '6'=>'Fasting serum gluc '),array('empty'=>'select Type'))

			'value' => $fillable->dropDownList($model2,'TEST_ID',CHtml::listData(DRITABLEMAPPING::model()->findAll(array('order'=>'ID')),'ID','TEST_NAME'),array('empty'=>'select')),

			

         ),




      ),

      'CButtonColumn' => array(

         'button' => '<a href="'.Yii::app()->createUrl('DRIMSTRTRIALGRIDTEST/create').'"><img style="vertical-align: middle;" src="'. Yii::app()->baseUrl .'/images/ico_plus.gif" alt="plus"></a>',

         'action' => Yii::app()->createUrl('DRIMSTRTRIALGRIDTEST/create'),

      ),

      'position' => 'top',

   ),


	'columns'=>array(

		//'ID',

		'MSTR_TRIAL_ID.name',

		//'TEST_ID',

			

		array(

                  'name'=>'TEST_ID',	

				  //'value'=>array($this,'tabmapping'), 

				  //'value'=>'dRITABLEMAPPING::model()->FindByPk(data->TEST_ID)->TEST_NAME'

				  'value'=>'DRIMSTRTRIAL::getTESTID($data->TEST_ID)',  

					

					  

			  ),

		array(

			'class'=>'CButtonColumn',

			 'template'=>'{view}{update}{delete}',

			 'buttons'=>array

					(

				'update' => array

					(

					'label'=>'Update',

					//'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',

					'url'=>'Yii::app()->createUrl("/DRIMSTRTRIALGRIDTEST/update", array("id"=>$data->ID))',

					),

				'view' => array

					(

					'label'=>'View',

					//'imageUrl'=>Yii::app()->request->baseUrl.'/images/view.png',

					'url'=>'Yii::app()->createUrl("/DRIMSTRTRIALGRIDTEST/view", array("id"=>$data->ID))',

					),

				'delete' => array

					(

					'label'=>'Delete',

					//'imageUrl'=>Yii::app()->request->baseUrl.'/images/delete.png',

					'url'=>'Yii::app()->createUrl("/DRIMSTRTRIALGRIDTEST/delete", array("id"=>$data->ID))',

					),

				'deleteConfirmation'=>"js:'Do you really want to delete record with ID '+$(this).parent().parent().children(':nth-child(2)').text()+'?'",

				

				),

                   

		),

	),

)); ?>







'MSTR_TRIAL_ID.name',

When i try to implement in fillable the widget is breaking? Please let me know if relation can me implemented in fillable

Hello,

I installed the extension, but I do not understand where the bug is.

I installed however when completing the fields as soon as I switch to another field there is the small icon and automatically loading all the fields are empty.

I really need your help pleeeaaaaazzz. pity.

Ill rewrite this extension at this week - it not work properly.

Also I want use dnsmasq instead isc-dhcp - it know work as name server for zone local.

The EXTENSION dhcp-server, you can only in english save. In German save, nothing change.