public function generateColumns() { $p = 0; $last = count($this->columns) - 1; foreach ($this->columns as $k => $column) { $this->dcolumns[$p] = new StdClass(); $this->dcolumns[$p]->id = $p; $this->dcolumns[$p]->field = $column->field ?: 'field' . $p; if ($column instanceof MGridAction) { if ($column->type == 'select') { $rowCount = count($this->data); $control = new MCheckBox($this->id . "chkAll", 'chkAction', ''); $control->addEvent('click', $this->id . ".checkAll({$rowCount});", false); $this->dcolumns[$p]->className = 'select'; } elseif ($column->type == 'icon') { $control = new MDiv('', '', 'managerIcon'); $this->dcolumns[$p]->className = 'actionIcon'; } elseif ($column->type == 'text') { $control = new MDiv('', '', ''); } $this->dcolumns[$p]->sortable = false; } elseif ($column instanceof MGridColumn) { if (!$column->visible) { continue; } $control = new MDiv('', $column->title, ''); $class = $column->getClass(); if ($class) { $this->dcolumns[$p]->className = $class; } $this->dcolumns[$p]->sortable = !$column instanceof MGridControl; } $this->dcolumns[$p++]->label = $control->generate(); } }
public static function select($action, $i, $row) { $index = $row[$action->grid->index]; $control = new MCheckBox($action->id . "[{$action->grid->currentIndex}]", $index, '', array_search($index, $action->grid->selecteds) !== false); $control->addEvent('click', "{$action->grid->name}.check({$action->grid->currentIndex},{$index});", false); return $control; }
public function generateTable() { $width = $this->scrollable ? $this->scrollWidth - 25 . 'px' : $this->width; $table = new MSimpleTable($this->id, array("width" => $width, "class" => "mGrid")); $p = 0; $last = count($this->columns) - 1; foreach ($this->columns as $k => $column) { if ($column instanceof MGridAction) { if ($column->type == 'select') { $rowCount = count($this->data); $this->page->onLoad("{$this->name}.idSelect = '{$this->idSelect}';"); $this->page->onLoad("{$this->name}.firstIndex = {$this->firstIndex};"); $check = new MCheckBox($this->name . "chkAll", 'chkAction', ''); $check->addEvent('click', $this->name . ".checkAll({$rowCount});"); $table->setHead($p, $check); $table->setHeadClass($p++, 'select'); } elseif ($column->type == 'icon') { $table->setHead($p, new MDiv('', '', 'managerIcon')); $table->setHeadClass($p++, 'action'); } elseif ($column->type == 'text') { $table->setHead($p++, new MDiv('', '', '')); } } elseif ($column instanceof MGridColumn) { if (!$column->visible) { continue; } if ($column->order) { $this->orderBy = $k; $link = new MLinkButton('', $column->title, $this->getURL($this->filtered, true)); $link->setClass('order'); $colTitle = $link; $table->setHeadClass($p, 'order'); } else { $colTitle = $column->title; } if ($column->width) { $attr = $k != $last ? " width=\"{$column->width}\"" : ''; //" width=\"100%\""; } $table->setHead($p++, $colTitle); } } if ($this->data) { // generate data rows $i = 0; $firstRow = true; foreach ($this->data as $row) { // foreach row $this->currentRow = $i; $this->currentIndex = $this->firstIndex + $i; $rowId = $i % 2; $rowClass = $this->alternateColors ? "row{$rowId}" : "row"; if ($this->dnd) { $rowClass .= ' dojoDndItem'; } if ($this->lookupName != '') { $rowClass .= ' rowLookup'; } $c = $this->hasDetail ? $i + $this->currentRow : $i; $i++; //$table->setRowAttribute(0, "id", 'tbody' . $this->id . 'first'); $table->setRowAttribute($c, 'id', $this->name . "-row-" . $this->currentIndex); $table->setRowClass($c, $rowClass); $this->generateColumnsControls($this->currentRow, $row); $this->callRowMethod(); // generate Columns $row = $this->currentRow; $p = 0; //$last = count($this->columns) - 1; foreach ($this->columns as $k => $column) { $control = $column->control[$row]; if ($column instanceof MGridAction) { if ($column->type == 'select') { $table->setCellClass($row, $p, 'select'); } elseif ($column->type == 'icon') { $table->setCellClass($row, $p, 'actionIcon'); } $table->setCell($row, $p++, $control); //} elseif ($column instanceof MGridActionText) { //$table->setCellClass($row, $p, 'actionText'); // $table->setCell($row, $p++, $control); } elseif ($column instanceof MGridColumn) { if (!$column->visible) { continue; } if ($column->width && $firstRow) { //$attr = ($k != $last) ? " width=\"$column->width\"" : " width=\"100%\""; $attr = " width=\"{$column->width}\""; $table->setCellAttribute($row, $p, $attr); } if ($column->nowrap) { $table->setCellAttribute($row, $p, "nowrap"); } if (trim($column->align)) { $table->setCellAttribute($row, $p, "style='text-align:{$column->align}'"); } $class = $column->getClass(); if ($class) { $table->setCellClass($row, $p, $class); } $table->setCell($row, $p++, $control); } } $firstRow = false; // end generate columns } // end foreach row } // end if return $table; }