| Id | Surname | Name | Sex | Children | Born | Dead | |
|---|---|---|---|---|---|---|---|
| 54 | 885 | female | 0 | 0 | 1970/01/01 | 1970/01/01 | |
| 57 | female | 0 | 100 | 1970/01/01 | 1970/01/01 | ||
| 59 | male | 0 | 0 | 1970/01/01 | 1970/01/01 | ||
| 71 | male | 0 | 1 | 1970/01/01 | 1970/01/01 | ||
| 72 | male | 0 | 0 | 1970/01/01 | 1970/01/01 | ||
| 73 | male | 0 | 0 | 1970/01/01 | 1970/01/01 | ||
| 77 | male | 0 | 0 | 1970/01/01 | 1970/01/01 | ||
| 80 | klodsfsdf | male | 0 | 0 | 1970/01/01 | 1970/01/01 | |
| 81 | aaa | female | 0 | 111 | 1970/01/01 | 1970/01/01 | |
| 82 | male | 0 | 0 | 1970/01/01 | 1970/01/01 | ||
| 84 | kvakva | male | 0 | 0 | 1970/01/01 | 1970/01/01 | |
| 96 | male | 16 | 0 | 1970/01/01 | 1970/01/01 | ||
| 98 | female | 0 | 0 | 1970/01/01 | 1970/01/01 | ||
| 100 | fff | female | 0 | 0 | 1970/01/01 | 1970/01/01 | |
| 103 | ccool | male | 0 | 0 | 1970/01/01 | 1970/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.