-
Notifications
You must be signed in to change notification settings - Fork 0
/
EEditableColumn.php
64 lines (63 loc) · 2.19 KB
/
EEditableColumn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* EEditableColumn
*
* Creates an editable column in your CGridView.
*
* please refer to README.md for an example.
*
* @uses CDataColumn
* @author Cristian Salazar H. <[email protected]> @salazarchris74
* @license FreeBSD {@link http://www.freebsd.org/copyright/freebsd-license.html}
*/
class EEditableColumn extends CDataColumn {
public $editable_type; // "editbox","select" (required array in editable_options)
public $editable_options; // array(1=>'yes',0=>'no')
public $action; // the action receptor when receiving changes.
// array('someaction')
public $input_options; // array('data-mask'=>'000-000', 'class'=>'my')
public function renderDataCell($row)
{
$dummy = new EEditable($this->grid->id);
$data=$this->grid->dataProvider->data[$row];
$options=$this->htmlOptions;
if($this->cssClassExpression!==null) {
$class=$this->evaluateExpression($this->cssClassExpression,
array('row'=>$row,'data'=>$data));
if(!empty($class)){
if(isset($options['class']))
$options['class'].=' '.$class;
else
$options['class']=$class;
}
}
if(null != $this->editable_type){
$options['editable_type'] = $this->editable_type;
$options['editable_name'] = $this->name;
$keyValue = "0";
if(isset($this->grid->dataProvider->keyField)){
$dpKeyField = $this->grid->dataProvider->keyField;
if(!isset($data[$dpKeyField]))
throw new Exception("The provided keyField '$dpKeyField' "
."is not defined in your data columns or array indexes");
$keyValue = $data[$dpKeyField];
}else{
$keyValue = $data->primarykey;
}
$options['editable_action'] = CHtml::normalizeUrl($this->action);
$options['editable_id'] = $keyValue;
if($this->input_options) $options['editable_data'] =
new CJavaScriptExpression("[".CJavaScript::encode(
$this->input_options)."]");
}
echo CHtml::openTag('td',$options);
if($this->editable_type=='select'){
echo "\n<select class='editable_options' style='display:none;'>\n";
foreach($this->editable_options as $value=>$label)
echo "\t<option value='$value'>$label</option>\n";
echo "</select>\n";
}
$this->renderDataCellContent($row,$data);
echo '</td>';
}
}