Makes a CGridView column to be editable. Can be used outside Yii Framework too.
JavaScript PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


EEditable is a jQuery extension for Yii Framework applications enabling your application to make a tag editable by the end user. A Special class is provided for CGridView: EEditableColumn, this class enabling your CGridView to make an editable column.

Example Example

This extension is designed to be used with/without Yii Framework application this not limit the usage outside the Yii Framework limits, please refeer to the first example below this lines to know how.

##Example 1: In a non-yiiframework application.

<table id='some'>
		<!-- this will select a editbox when clicking over it -->
		<td editable_type='editbox' 
			editable_action='some url to send a post via ajax request'
			editable_id='someUniqueId', editable_name='someColName1'>
			value to be edited when clicking over it
		<!-- this will display a select having the values provided 
		in the inner select tag -->
		<td editable_type='select' 
			editable_action='some url to send a post via ajax request'
			editable_id='someUniqueId', editable_name='someColName2'>
				<select style='display:none;' class='editable_options'>
					<option value='1'>Yes</option>
					<option value='0'>No</option>

##Example 2: In a Yii Framework application: As a CGridView column.

This jQuery Extension can be used via special column inserted into your CGridView, using the attribute: class='EEditableColumn'.


$grid_id = 'some-grid-view';
$this->widget('zii.widgets.grid.CGridView', array(
			'class'=>'EEditableColumn', 'editable_type'=>'editbox',
			// see also: 'How-To Customize the User Input' about more attributes.
			'class'=>'EEditableColumn', 'editable_type'=>'select',

#At Server Side

This jQuery extension send a POST to the action defined in the tag attribute named: 'editable_action'. When used as a EEditableColumn then this url is provided via 'action' option (example: 'action'=>array('/some/ajaxeditcolumn')). The action send a POST (via ajax) to your server having this keys:

keyvalue	commonly identifyes the primary key value
name		the 'name' attribute value in your column definition
old_value	the original value previous to edition
new_value	the new value typed by the end user

As return, the ajax call expects from you to 'echo' the accepted value.

public function actionAjaxEditColumn(){
	$keyvalue	= $_POST["keyvalue"];  	// ie: 'userid123'
	$name		= $_POST["name"];	// ie: 'firstname'
	$old_value  = $_POST["old_value"];	// ie: 'patricia'
	$new_value  = $_POST["new_value"];	// ie: '  paTTy '

	// do some stuff here, and return the value to be displayed..
	$new_value = ucfirst(trim($new_value));
	echo $new_value;			// Patty

#How-To Customize the User Input

The following item is related to YiiFramework. (For non-yiiframework applications take a look at raw html to see how it works, is very easy).

Two things comes in help with this issue:

a) The attribute 'input_options', is an array declared for each column defining customized values for the input element.


b) An optional callback js function declared in your page having this format, it will be used only if declared:

		called only if declared. hardwired.

	 	event_name	string	'on_create', 'on_ajax'
		input		object	the jquery wrapped input object
		tag			object	the jquery wrapped object containing more info
	function eeditable_callback(event_name, input,tag){
		if('on_create' == event_name) {
			// example using the jQuery.mask plugin
			if(undefined != input.attr('data-mask'))
		if('on_ajax' == event_name){
			return true;

#Exception Thrown when using CArrayDataProvider, why ?

An exception is thrown when a CArrayDataProvided is used and when the keyField is not defined:

The provided keyField 'id' is not defined in your data columns or array indexes 

How to fix:

Set a value in the 'keyField' attribute, look at the provided example below this lines:

$yourData = array(array("firstname"=>"jhonn","lastname"=>"doe"), ... );
$dp = new CArrayDataProvider($yourData,array(

When using this extension on a CActiveDataProvider then this problem doesn't occurs.

#Implementing CSRF Tokens

Please refeer to issue #4 to know more about how to successfully implement a CSRF token. (Thanks to: Daniel)