Exemple #1
0
 /**
  * Add action to the datagrid
  * @param $label  Action Label
  * @param $action TAction Object
  * @param $icon   Action Icon
  */
 public function addQuickAction($label, TDataGridAction $action, $field, $icon = 'ico_save.png')
 {
     $action->setLabel($label);
     $action->setImage($icon);
     $action->setField($field);
     // add the datagrid action
     parent::addAction($action);
 }
 public function addParsedObject($object)
 {
     if ($object instanceof TFilterCollection) {
         $this->_filterCollection = $object;
         $this->getControls()->add($this->_filterCollection);
     } else {
         parent::addParsedObject($object);
     }
 }
 /**
  * 
  */
 public function makeTDataGrid($properties)
 {
     $table = new TTable();
     $widget = new TDataGrid();
     $widget->setHeight((string) $properties->{'height'});
     if ($properties->{'columns'}) {
         foreach ($properties->{'columns'} as $Column) {
             $dgcolumn = new TDataGridColumn((string) $Column->{'name'}, (string) $Column->{'label'}, (string) $Column->{'align'}, (string) $Column->{'width'});
             $widget->addColumn($dgcolumn);
             $this->fieldsByName[(string) $Column->{'name'}] = $dgcolumn;
         }
     }
     if ($properties->{'actions'}) {
         foreach ($properties->{'actions'} as $Action) {
             $dgaction = new TDataGridAction(array($this->controller, (string) $Action->{'method'}));
             $dgaction->setLabel((string) $Action->{'label'});
             $dgaction->setImage((string) $Action->{'image'});
             $dgaction->setField((string) $Action->{'field'});
             $widget->addAction($dgaction);
             //$this->fieldsByName[(string)$properties->Name] = $column;
         }
     }
     if ((string) $properties->{'pagenavigator'} == 'yes') {
         $loader = (string) $properties->{'loader'} ? (string) $properties->{'loader'} : 'onReload';
         $pageNavigation = new TPageNavigation();
         $pageNavigation->setAction(new TAction(array($this->controller, $loader)));
         $pageNavigation->setWidth($widget->getWidth());
     }
     $widget->createModel();
     $row = $table->addRow();
     $row->addCell($widget);
     if (isset($pageNavigation)) {
         $row = $table->addRow();
         $row->addCell($pageNavigation);
         $widget->setPageNavigation($pageNavigation);
     }
     $this->fieldsByName[(string) $properties->{'name'}] = $widget;
     $widget = $table;
     return $widget;
 }
 /**
  * Renders the datagrid by writing a div tag with the container id obtained from {@link getSurroundingTagId()}
  * which will be called by the replacement method of the client script to update it's content.
  * @param THtmlWriter writer for the rendering purpose
  */
 private function renderDataGrid($writer)
 {
     $writer->write('<div id="' . $this->getSurroundingTagId() . '">');
     parent::render($writer);
     $writer->write('</div>');
 }
 /**
  * Removes the item from the body collection.
  * This method will be invoked when an item is to be removed from the collection.
  * @param mixed the item to be removed.
  */
 protected function onRemoveItem($item)
 {
     $this->grid->getBodies()->remove($item);
 }
Exemple #6
0
 /**
  * Renders the datagrid by writing a {@link getSurroundingTag()} with the container id obtained
  * from {@link getSurroundingTagId()} which will be called by the replacement method of the client
  * script to update it's content.
  * @param THtmlWriter writer for the rendering purpose
  */
 private function renderDataGrid($writer)
 {
     $writer->addAttribute('id', $this->getSurroundingTagID());
     $writer->renderBeginTag($this->getSurroundingTag());
     parent::render($writer);
     $writer->renderEndTag();
 }
    switch ($sexo) {
        case 'M':
            return 'Masculino';
            break;
        case 'F':
            return 'Feminino';
            break;
    }
}
// declara a classe Pessoa
class Pessoa extends TRecord
{
    const TABLENAME = 'pessoa';
}
// instancia objeto DataGrid
$datagrid = new TDataGrid();
// instancia as colunas da DataGrid
$codigo = new TDataGridColumn('id', 'Código', 'right', 50);
$nome = new TDataGridColumn('nome', 'Nome', 'left', 160);
$endereco = new TDataGridColumn('endereco', 'Endereço', 'left', 140);
$datanasc = new TDataGridColumn('datanasc', 'Data Nasc', 'left', 100);
$sexo = new TDataGridColumn('sexo', 'Sexo', 'center', 100);
// aplica as funções para transformar as colunas
$nome->setTransformer('strtoupper');
$datanasc->setTransformer('conv_data_to_br');
$sexo->setTransformer('get_sexo');
// adiciona as colunas à DataGrid
$datagrid->addColumn($codigo);
$datagrid->addColumn($nome);
$datagrid->addColumn($endereco);
$datagrid->addColumn($datanasc);
<?php

/*
 * função __autoload()
 * carrega uma classe quando ela é necessária,
 * ou seja, quando ela é instancia pela primeira vez.
 */
function __autoload($classe)
{
    if (file_exists("app.widgets/{$classe}.class.php")) {
        include_once "app.widgets/{$classe}.class.php";
    }
}
// instancia objeto DataGrid
$datagrid = new TDataGrid();
// instancia as colunas da DataGrid
$codigo = new TDataGridColumn('codigo', 'Código', 'left', 50);
$nome = new TDataGridColumn('nome', 'Nome', 'left', 180);
$endereco = new TDataGridColumn('endereco', 'Endereço', 'left', 140);
$telefone = new TDataGridColumn('fone', 'Fone', 'center', 100);
// adiciona as colunas à DataGrid
$datagrid->addColumn($codigo);
$datagrid->addColumn($nome);
$datagrid->addColumn($endereco);
$datagrid->addColumn($telefone);
// instancia duas ações da DataGrid
$action1 = new TDataGridAction('onDelete');
$action1->setLabel('Deletar');
$action1->setImage('ico_delete.png');
$action1->setField('codigo');
$action2 = new TDataGridAction('onView');