Trait kartik\grid\controllers\GridEditedRowTrait
Implemented by | kartik\grid\controllers\GridEditedRowController |
---|
GridEditedRowTrait implements the specific actions and methods that can be used in any of controllers to
enable the Krajee GridView edited row functionality. You must define a property called editedRowConfig
in your
controller and use this trait. The property must match the kartik\grid\GridView::$editedRowConfig property specification.
This trait is used by kartik\grid\controllers\GridEditedRowController which can alternatively be extended by your own controller classes.
For example:
class BookController extends \yii\web\Controller {
use \kartik\grid\controllers\GridEditedRowTrait;
// @var array the configuration for the row being currently edited
public $editedRowConfig = [
'rowIdGetParam' => 'row',
'gridIdGetParam' => 'grid',
'gridFiltersSessionParam' => 'kvGridFiltersCache',
'highlightClass' => 'kv-row-edit-highlight',
];
// your model UPDATE action
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', "Updated book # {$id} successfully.");
return $this->redirectIndex($id); // USE this for redirecting to edited row
} else {
return $this->render('update', ['model' => $model, ]);
}
}
}
On your view file (for update or view) - you can create a Cancel button to go back to the edited row, using the back action. For example,
use yii\helpers\Html;
echo Html::a('Cancel', ['back', 'id' => $model->id], ['class' => 'btn btn-primary', 'title' => 'Go back']);
See also [[kartik\grid\controllers\GridEditedRowController]].
Public Methods
Method | Description | Defined By |
---|---|---|
actionBack() | Go back to main index page. Use this action as a link button in your other views for cancelling and going back to the index page with the highlighted edited row. | kartik\grid\controllers\GridEditedRowTrait |
Protected Methods
Method | Description | Defined By |
---|---|---|
getQueryParamsCached() | Gets the cached query parameters from session for navigating to the just edited row | kartik\grid\controllers\GridEditedRowTrait |
redirectIndex() | Redirects to index page with cached query params containing the highlighted edited row | kartik\grid\controllers\GridEditedRowTrait |
Method Details
Go back to main index page. Use this action as a link button in your other views for cancelling and going back to the index page with the highlighted edited row.
public yii\web\Response actionBack ( $id = null ) | ||
$id | integer|string | The record identifier |
Gets the cached query parameters from session for navigating to the just edited row
protected array getQueryParamsCached ( $id ) | ||
$id | integer|string | The record identifier |
Redirects to index page with cached query params containing the highlighted edited row
protected yii\web\Response redirectIndex ( $id, $grid = null ) | ||
$id | integer|string | The record identifier |
$grid | string | The grid identifier |