Exemplo n.º 1
0
 public static function columns(&$grid, $columns)
 {
     //
     foreach ($columns as $k => $v) {
         $html = false;
         $alias = false;
         $field = $k;
         $visible = true;
         $sortable = true;
         $width = 0;
         $function = false;
         if (is_array($v)) {
             if (isset($v['field'])) {
                 $alias = $k;
                 $field = $v['field'];
             } else {
                 if (isset($v['alias'])) {
                     $alias = $v['alias'];
                 }
             }
             $html = isset($v['html']) ? $v['html'] : false;
             $label = isset($v['label']) ? $v['label'] : $field;
             $width = isset($v['width']) ? (int) $v['width'] : 0;
             $sortable = isset($v['sortable']) ? (bool) $v['sortable'] : true;
             $visible = isset($v['visible']) ? (bool) $v['visible'] : true;
             $function = isset($v['function']) ? $v['function'] : false;
         } else {
             $field = $k;
             $label = $v;
         }
         // prepare column object
         $column = new GridColumn();
         // set a css class for this column
         if (isset($v['class']) && $v['class']) {
             $column->setCssClass($v['class']);
         }
         $column->setHtml($html);
         $column->setAlias($alias);
         $column->setField($field);
         $column->setLabel($label);
         $column->setWidth($width);
         $column->setSortable($sortable);
         $column->setVisible($visible);
         $column->setFunction($function);
         //$column->setReadOnly(false);
         //
         $grid->addColumn($column);
     }
 }