Extension a basic set of columns of Yii grid. Allows you to organize interactive editing data inside the grid. The new values will be sent to the server using Ajax. At the moment includes:
Testing with Yii 1.1.7, but should work since Yii 1.1.
Choose your favourite of - GPL or MIT.
...
'application.extensions.phaActiveColumn.*',
...
Now in your template you can use the new column. All new collumns must set property actionUrl. It's URL for update action.On this URL will be sent call to update value. If this value is string - value will be used as is. If it's array - will be called CHtml::normalizeUrl.
Because the column type phaSelectColumn is inherited from CDataColumn and CGridColumn, it includes entire set of properties and methods of base classes. Consider the different properties:
For example, consider building an interactive grid to edit a list of cities and time zones for this cities:
$this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, 'columns'=>array( ........... array ( 'class' => 'phaSelectColumn', 'header' => 'Time Zone', 'name' => 'time_zone_id', 'data' => CHtml::listData(TimeZones::model()->findAll(), 'id', 'name'), 'actionUrl' => array('setTimeZone'), ), ........... ), ));
After changing any values will be send a POST request, containing:
For data that have two states is convenient use a column of phaCheckColumn type. In this column will display the checkbox when the status is change, the new value will be send to server.
For example, consider building an interactive grid to activate same item:
$this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, 'columns'=>array( ........... array( 'class' => 'phaCheckColumn', 'name' => 'is_active', 'actionUrl' => array('setIsActive'), ), ........... ), ));
After changing any values will be send a POST request, containing:
If you need edit text date without open other page, you can use this type of column. In normal state it's view data as ordinary column. But click on data cell will open input field for edit data. After press Enter new data will be send to server.
We add column phaEditColumn type for editing attribute name of model.
$this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, 'columns'=>array( ........... array( 'class' => 'phaCheckColumn', 'name' => 'name', 'actionUrl' => array('setName'), ), ........... ), ));
After changing any values will be send a POST request, containing:
If you click on row, view data will change to input field. Enter send data to server, and ESC-key will close input without send data.
Total 13 comments
It has been reported previously, but blank fields are not shown by phaEditColumn.
My solution was to substitute a "-" character in the displayed value. This is done in phaEditColumn.php
Several others noted that phaEditColumn will submit the correct URL if used with only one column in the grid because the same key (grid id) is repeatedly used when populating the phaACActionUrls[] array. In comment #7902, jwerd (no relation to jward) was on the right track when $data->id was tried. It only takes a few more changes to complete a fix.
I modified the script in init(). You can spot my changes by finding the commented lines:
Hey there,
Just thought I'd let you know that the latest version still has issues with the url only working for one field.
But I think I know why, question is, how can we go about fixing it? First here's my entire widget call:
Now, the generated code that concerns me is:
It appears to just override because the $data->grid->id is the same on all of them. When I switch this to $data->id, it starts posting to the same page the grids on, completely ignoring the url.
Any ideas? Thanks in advance!
It isn't work.
It solved only by class in htmlOptions + css
HI, I tried with CArrayDataProvider, and don't fork for me. First I see that the field is created with this id and class:
the id look not ok for me, So i check inside phaEditColumn.php and I found this:
where $valueId is used to define the field ID:
I'll try to asign the field manually.
Regards.
I think it must work by default.
I have prepared a new version that solves this problem with different URL. But I would like to clarify, does not solve the problem of empty fields use htmlOptions option for a cell?
Thank you very much for update!
But now i have another problem (= When i use several editable columns, working only last 'actionUrl' and name of column is don't send with ajax post. So i can have only one phaEditColumn in grid.
see on string 117
I tried to fix it. Maybe it help you again. http://dl.dropbox.com/u/11392265/temp/phaEditColumn.php
Also I add after 34 string
for edit empty field
And width: 100% needed for more big click-area
to lkg0dzre: Thx for your version of the code, it helped me understand the problem. The best way to add style to an element to be used in the configuration of the column:
to Nicolas400: I use CActiveDataProvider. But I think CArrayDataProvider will not have problems with this extension, becouse it exted base column class only. If you have any problem with this extension - write report, I will fix it :)
hi, I think this is what I need. Do you use it with CArrayDataProvider ? Best Regards.
I tried to fix it. Maybe it help you. http://dl.dropbox.com/u/11392265/temp/phaEditColumn.php
I'm not counting on such a possibility :) ок, I will include it in the coming version. Thank you for using and reporting!
phaEditColumn is not working with several grids
Thx for extension!
Leave a comment
Please login to leave your comment.