Created
July 1, 2011 14:40
-
-
Save MartyIX/1058684 to your computer and use it in GitHub Desktop.
Grinder PHP Nette
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
protected function createComponentGrinder() | |
{ | |
$model = new Grinder\Models\DibiFluentModel($this->getModel('orders')->getFluentForYourEvents()); | |
$grid = new Grinder\Grid($model); | |
$grid->setRenderer(new Grinder\Renderers\TableRenderer); | |
// if not present then $this->session is not initialized in grid.php and you'll get an exception | |
$grid->setUpProtection($this->getSession()); | |
$grid->setItemsPerPage(2); | |
// If you want to add a select box (for deleting and other batch operations) | |
// $grid->addCheckColumn('select'); | |
// How to add filter for your column. Grinder handles DateTime and displays the date in a readable format (which can be changed). | |
$grid->addColumn('when', 'Koná se')->addFilter(function ($value) { return new \DateTime($value);}); | |
$grid->addColumn('content', 'Školení'); | |
$grid->addColumn('city', 'Město'); | |
// Boolean values are handled and as output on your screen you'll get "Yes"/"No" values | |
//$grid->addColumn('participated', 'Účast')->addFilter(function ($value) { return (bool)$value;}); | |
// ... or you can use \Nette\Html and display an image styled via CSS | |
$grid->addColumn('participated', 'Účast')->addFilter(function ($value) { | |
if ($value) { | |
$el = Html::el("span")->class("icon icon-accept"); | |
} else { | |
$el = Html::el("span")->class("icon icon-delete"); | |
} | |
return $el; | |
}); | |
$grid->addColumn('status', 'Stav')->addFilter(function ($value) { | |
$arr = array( | |
0 => "Zpracovává se", | |
1 => "Potvrzeno", | |
2 => "Zamítnuto" | |
); | |
return $arr[$value]; | |
}); | |
$icon = Html::el('span'); | |
$grid->addColumn('passed', 'Test')->addFilter(function ($value) { return (bool)$value;}); | |
// ==== There must be an easier way how to do this complex behavior with addActions ===== | |
$_this = $this; | |
$grid->addColumn('f_id', '')->addFilter(function ($value, $record) use ($icon, $_this) { | |
$res = Html::el('div'); | |
$ic = Html::el("span")->class("icon icon-attach"); | |
if ($record['f_id'] !== NULL) { | |
$icon1 = Html::el('a')->href($_this->lazyLink(':Main:Downloads:down',array('id'=>$record['f_id'])))->setHtml($ic); | |
$res->add($icon1); | |
} elseif ($record['url'] !== NULL) { | |
$icon1 = Html::el('a')->href($record['webex__record'])->setHtml($ic); | |
$res->add($icon1); | |
} | |
if ($_this->getModel('trainings')->isTrainingTypeExternal($record['trainings_type'])) { | |
$ic = Html::el('span')->setClass('icon icon-anchor'); | |
$icon2 = Html::el('a')->href($record['url'])->setHtml($ic); | |
$res->add($icon2); | |
} | |
return $res; | |
}); | |
/* | |
$grid->addAction('materials', clone $icon->setClass("icon icon-attach")) | |
->setLink($this->lazyLink(':Main:Downloads:down'), array('id' => 'f_id')) | |
->setVisible(function($record) { return $record['f_id'] !== NULL; }); // ====== actions can be hidden | |
*/ | |
// This works with uncommented 'select' item above | |
// $grid->addToolbarAction('send', 'Vypsat')->onSuccess[] = callback($this, 'DumpSubmitted'); | |
return $grid; | |
} | |
/** | |
* @param Kdyby\Components\Grinder\Toolbar\ButtonAction $grid | |
*/ | |
public function DumpSubmitted(\Kdyby\Components\Grinder\Actions\ButtonAction $action) | |
{ | |
dump($action->getGrid()->getColumn('select')->getChecked()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fixed ;)