efillablecgridview Creates a "add element" row in a CGridView

  1. Requirements
  2. Changelog
  3. Installation
  4. Usage
  5. Explanations

We sometimes want to add elements (lines) when being in "admin view", without changing the page we are on.

Requirements

Yii 1.1

Changelog

  • 10/14/2013 : Added the fillIsFilter option. When setted, the fillable row is also filtering the grid.

Installation

  1. Download the extension and extract the file in your protected/extensions/ directory
  2. Check that "application.extensions.*" is in your import array in your config file
  3. Follow the example code (Usage section)

Usage

This extension add a "fillable" section in a CGridView widget. Here is an example of the usage.

The grid contains 4 columns: ColId (id), MyCol1 (text), MyCol2 (text), MyCol3 (relationnal select). We want to add, at the end of the grid, a form with inputs for the fillable fields (not the id) and in the action column a "plus" icon to do the action.

$this->widget('application.extensions.EFillableCGridView', array(
   'id'=>'my-grid',
   'dataProvider'=>$model->search(),
   // **** Here starts the addition ****
   'fillable' => array(
      'columns' => array(
         array(
            'name' => 'MyCol1',
            'value' => CHtml::textField($model,'MyCol1')
         ),
         array(
            'name' => 'MyCol2',
            'value' => CHtml::textField($model,'MyCol2')
         ),
         array(
            'name' => 'MyCol3',
            'value' => CHtml::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',
      'fillIsFilter' => true,
   ),
   // **** Here ends the addition ****
   'columns'=>array(
      'ColId',
      'MyCol1',
      'MyCol2',
      array(
         'name' => 'MyCol3',
         'value' => '$data->Col3->nameCol3',
      ),
      array(
         'class'=>'CButtonColumn',
      ),
   ),
));

Explanations

The fillable section contains 4 subsections:

  • columns is the list of columns you want to add. Each column is defined with a name (must reflect the names used in the grid) and a value: the html input.

  • CButtonColumn is an array containing action (the action of the ajax form) and button, the html link you'll use to send the form.

  • position (optional) is where you want to have the form. Default is 'bottom' (after the last line, before footer), you can set it to 'top' (after the filters)

  • fillIsFilter (optional) allow the fillable row to also be a filter row. When setted to true (or 1, or anything you want), it is a filter until you submit the datas

3 0
11 followers
782 downloads
Yii Version: Unknown
License: GPL-3.0
Category: User Interface
Developed by: CrazyCat
Created on: Jul 17, 2013
Last updated: 10 years ago

Downloads

show all

Related Extensions