Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
update docs and enhance grid to run code
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydspaniard committed Jul 27, 2017
1 parent 4194643 commit feabd59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/grids/enhanced-grid-view.md
Expand Up @@ -7,8 +7,8 @@ to set behaviors dynamically on configuration.
On `renderSection()` the behaviors methods take priority over the GridView's thus providing a runtime override
mechanism.

At the end of `run()` method, it also checks if any of its behaviors extends from `RegistersClientScriptInterface` so
to register any javascript required.
At the end of `run()` method, it checks if any of its behaviors implement `RegistersClientScriptInterface` so
to register any javascript required and if they implements `RunnableBehaviorInterface` to run its internal code.

There is really not much more to say about this widget and thats the beauty of it. You should check
[how to create behaviors](../guides/how-to-create-behaviors.md) guide to find out how to extend this great piece of
Expand Down
10 changes: 7 additions & 3 deletions src/GridView.php
Expand Up @@ -10,6 +10,7 @@
namespace dosamigos\grid;

use dosamigos\grid\contracts\RegistersClientScriptInterface;
use dosamigos\grid\contracts\RunnableBehaviorInterface;
use yii\base\Behavior;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
Expand Down Expand Up @@ -81,13 +82,13 @@ public function run()
{
parent::run();

$this->registerClientScript();
$this->runBehaviors();
}

/**
* Registers required client scripts of behaviors
* Runs behaviors, registering their scripts if necessary
*/
protected function registerClientScript()
protected function runBehaviors()
{
$behaviors = $this->getBehaviors();

Expand All @@ -96,6 +97,9 @@ protected function registerClientScript()
if ($behavior instanceof RegistersClientScriptInterface) {
$behavior->registerClientScript();
}
if($behavior instanceof RunnableBehaviorInterface) {
$behavior->run();
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/contracts/RunnableBehaviorInterface.php
@@ -0,0 +1,11 @@
<?php

namespace dosamigos\grid\contracts;

interface RunnableBehaviorInterface
{
/**
* Runs code on render.
*/
public function run();
}

0 comments on commit feabd59

Please sign in to comment.