Tabella Example

basic complex editable download


Complex Tabella

IdSurnameNameSexChildrenBornDead
54885female001970/01/011970/01/01
57female01001970/01/011970/01/01
59male001970/01/011970/01/01
71male011970/01/011970/01/01
72male001970/01/011970/01/01
73male001970/01/011970/01/01
77male001970/01/011970/01/01
80klodsfsdfmale001970/01/011970/01/01
81aaafemale01111970/01/011970/01/01
82male001970/01/011970/01/01
84kvakvamale001970/01/011970/01/01
96male1601970/01/011970/01/01
98female001970/01/011970/01/01
100ffffemale001970/01/011970/01/01
103ccoolmale001970/01/011970/01/01

	  
	protected function createComponentComplexTabella($name) {

		$context = $this->context;

		$grid = new Tabella(array(
				'context'     => $this->context,
				'source'      => $this->context->model->users->source(),
				'order'       => 'surname',
				'limit'       => 15,
				'rowRenderer' => function($row) {
					return Html::el('tr')->class($row->sex);
				}
			));

		$grid->addColumn('Id', 'id', array(
			  		'width' => 30
			));

		$grid->addColumn('Surname', 'surname', array(
				'renderer' => function($row) use ($context) {
					// can be a link within the application
					return Html::el('td')->class('al')->add(Html::el('a')->target('_blank')
						->href($context->application->presenter
							->link('this', array(
								'complexTabella-filter' => array('id' => $row->id))))
						->add(Strings::truncate($row->surname, 25)));
					return $td;
		 		},
		 		// own filter handler which reacts on change in the filter input
		 		'filterHandler' => function($source, $value) {
					$source->where('surname')->like('%s', $value.'%');
		 		},
		 		'width' => 100
		));

		$grid->addColumn('Name', 'name', array(
				// own filter handler which reacts on change in the filter input
				'filterHandler' => function($source, $value) {
					$source->where('name')->like('%s', $value.'%');
				},
				'class' => array('center', 'upper'),
				// html class can be a string or array
				'width' => 100
		));

		$grid->addColumn('Sex', 'sex', array(
				'width' => 50,
				// makes selectbox filter
				'filter' => array('' => '', 'male' => 'male', 'female' => 'female'),
				'filterHandler' => function($source, $value) {
					$source->where('sex = %s', $value);
				}
		));

		$grid->addColumn('Children', 'children', array(
				'width' => 40,
				'filter' => array(
					'' => '',
					0 => 'having none',
					1 => 'having son',
					2 => 'having daughter',
					3 => 'having both'),
				'filterHandler' => function($source, $value) {
					switch($value) {
						case 0: $source->having('children = 0');
						case 1: $source->having('sons > 0');
						case 2: $source->having('daughters > 0');
						case 3: $source->having('sons > 0 AND daughters > 0');
					}
				},
				'headerElement' => Html::el('th')->colspan('2'),
				'renderer' => function($row) {
					$td = Html::el('td')->style('width:17px;')->add($row->sons).
							Html::el('td')->style('width:17px;')->add($row->daughters);
					return $td;
				}
		));

		$grid->addColumn('Born', 'born', array(
				'type' => Tabella::DATE,
				'class' => 'center',
				'dateFormat' => '%Y/%m/%d',
				'filterHandler' => function($source, $value) {
					$start = strtotime('$val 00:00');
					$end = $start + Nette\DateTime::DAY;
					$source->where('born > %i AND born < %i', $start, $end);
				}
		));
		$grid->addColumn('Dead', 'dead', array(
					'type' => Tabella::DATE,
				'class' => 'center',
					'dateFormat' => '%Y/%m/%d',
				'filterHandler' => function($source, $value) {
					$start = strtotime('$val 00:00');
					$end = $start + Nette\DateTime::DAY;
					$source->where('dead > %i AND dead < %i', $start, $end);
				}
		));

		$this->addComponent($grid, $name);
	}
	

(c) 2011 Vojtěch Knyttl, New BSD Licence. Tlumočení francouzštiny. Kulturní přehled.