Add columns to grid

@return Mage_Adminhtml_Block_Widget_Grid
965800
protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->removeColumn('customer_firstname');
        $this->removeColumn('customer_lastname');
        $this->addColumnAfter(
            'agreement_label', array(
            'header' => Mage::helper('sales')->__('Agreement Label'),
            'index' => 'agreement_label',
            'type' => 'text',
            ), 'status'
        );

        $this->addColumnAfter(
            'name', array(
            'header' => Mage::helper('customer')->__('Name'),
            'index' => 'name',
            'type' => 'text',
            'escape' => true
            ), 'customer_email'
        );

//        $status = $this->getColumn('status');
//        $status->setData('frame_callback', [$this, 'decorateStatus']);

        $createdAt = $this->getColumn('created_at');
        $createdAt->setData('index', 'created_at');

        $createdAt = $this->getColumn('updated_at');
        $createdAt->setData('index', 'updated_at');

        $this->sortColumnsByOrder();


        return $this;
    }
1116470
public function addColumns(array $columns)
    {
        /*
         * Build a final collection of list column objects
         */
        foreach ($columns as $columnName => $config) {
            $this->allColumns[$columnName] = $this->makeListColumn($columnName, $config);
        }
    }
1219644
protected function createComponentRolesList(): DataGrid
	{
		$grid = $this->dataGridFactory->create();

		$grid->setDataSource($this->orm->aclRoles->findRoles($this->viewSuperadmin));

		$grid->addColumnText('title', 'cms.permissions.role')
			->setEditableInputType('text')
			->setEditableCallback([$this, 'setRoleTitle']);

		$grid->addColumnText('name', 'cms.permissions.name')
			->setEditableInputType('text')
			->setEditableCallback([$this, 'setRoleName']);

		$grid->addColumnText('parent', 'cms.permissions.parent')
			->setRenderer(function (AclRole $role) {
				if (!empty($role->parent)) {
					return $role->parent->title;
				}
				return null;
			})
			->setEditableInputTypeSelect([0 => $this->translate('form.none')] + $this->orm->aclRoles->fetchPairs($this->viewSuperadmin))
			->setEditableCallback([$this, 'setRoleParent']);

		$grid->addAction('edit', null, 'editRolePermissions')
			->setIcon('pencil')
			->setTitle('default.edit');

		$grid->addAction('delete', null, 'deleteRole!')
			->setIcon('trash')
			->setTitle('default.delete')
			->setClass('btn btn-xs btn-danger ajax')
			->setConfirm(function (AclRole $role) {
				return $this->translate('cms.permissions.confirmDeleteRole', 1, ['name' => $role->title]);
			});

		$add = $grid->addInlineAdd()
			->setPositionTop()
			->setTitle('cms.permissions.addRole');
		$add->onControlAdd[] = [$this, 'roleForm'];
		$add->onSubmit[] = [$this, 'addRole'];

		$grid->addGroupAction('default.delete')->onSelect[] = [$this, 'deleteRoles'];

		return $grid;
	}
890383
public function html()
    {
        return $this->builder()
                    ->columns($this->getColumns())
                    ->postAjax()
                    ->parameters($this->getBuilderParameters());
    }
1173130
public function columns()
    {
        $fields = array(
            'Title' => array(
                'link' => function ($value, $item) {
                    $pageAdminLink = singleton(CMSPageEditController::class)->Link('show');
                    return sprintf('<a href="%s/%s">%s</a>', $pageAdminLink, $item->Link, $value);
                }
            ),
            'WorkflowStatus' => array(
                'text' => function ($value, $item) {
                    return $item->WorkflowCurrentAction;
                }
            )
        );
        return $fields;
    }
1168867
protected function createComponentList(): DataGrid
	{
		$grid = $this->dataGridFactory->create();
		$grid->setDataSource($this->orm->pages->findMain());
		$grid->setSortable();
		$grid->setTreeView([$this, 'getChildren'], 'hasChildren');
		$grid->setOuterFilterRendering();
		$grid->onRedraw[] = function () use ($grid) {
			if ($this->isAjax() && $grid['filter']->isSubmitted())
				$grid->redrawControl('grid');
		};

		$grid->addColumnText('name', 'webManager.web.pages.name', '_pages.name')
			->setTemplate(__DIR__ . '/templates/Pages/name.latte')
			->setFilterText();

		$grid->addColumnText('url', 'default.url')
			->setFilterText();

		$grid->addColumnText('locale', 'webManager.web.pages.locale')
			->setRenderer(function (Page $page) {
				return $page->locale->name;
			})
			->setFilterSelect($this->localeService->allowed);

		$grid->addColumnText('views', 'webManager.web.pages.views.title')
			->setRenderer(function (Page $row) {
				return implode(', ', $row->getViews());
			})
			->setFilterSelect(['' => 'form.none'] + $this->orm->pagesViews->fetchUntranslatedPairsById(), 'views.id')
			->setTranslateOptions();

		$grid->addAction('visibility', null, 'visibility!')
			->setTitle('webManager.web.pages.visibility')
			->setClass(function (Page $page) {
				return $page->visible ? 'btn btn-xs btn-success ajax' : 'btn btn-xs btn-default ajax';
			})
			->setIcon(function (Page $page) {
				return $page->visible ? 'eye' : 'eye-slash';
			});

		$grid->addAction('add', null)
			->setIcon('plus')
			->setTitle('webManager.web.pages.add');

		$grid->addAction('edit', null)
			->setIcon('pencil')
			->setTitle('default.edit');

		$grid->addAction('delete', null, 'delete!')
			->setIcon('trash')
			->setTitle('default.delete')
			->setClass('btn btn-xs btn-danger ajax')
			->setConfirm(function (Page $page) {
				return $this->translate('default.confirmDelete', 1, ['name' => $page->name]);
			});

		$grid->setDefaultFilter(['locale' => $this->localeService->defaultLocaleId]);

		$grid->allowRowsAction('add', function (Page $page) {
			return !$page->isHomePage;
		});

		return $grid;
	}
753870
public function addColumn($defaults = null)
    {
        $c = parent::addColumn($defaults);

        return $c->add([$this->formLayout, 'form' => $this->form]);
    }
1084328
protected function addRow()
    {
        $arguments = func_get_args();

        // store the longest column so we can pad out to it on render
        foreach ($arguments as $key => $value) {
            $columnLength = strlen($value);

            if (!isset($this->columnLengthMax[$key]) || $columnLength > $this->columnLengthMax[$key]) {
                $this->columnLengthMax[$key] = $columnLength;
            }
        }

        $this->rows[] = $arguments;
    }
1073321
private function add()
    {
        $columns = [];
        $values = [];
        //
        if ($this->_tracked) {
            $this->created_at = Time::current();
        }
        //
        foreach ($this->_columns as $value) {
            if ($value != $this->_keyName && isset($this->$value) && !empty($this->$value)) {
                $columns[] = $value;
                $values[] = $this->$value;
            }
        }
        //
        return $this->insert($columns, $values);
    }
539452
public function getColumns()
    {
        if (null === $this->_cols) {
            $this->_setupMetadata();
            $this->_cols = array_keys($this->_metadata);
        }
        return $this->_cols;
    }
1296900
protected function _getCols()
    {
        if (null === $this->_cols) {
            $this->_setupMetadata();
            $this->_cols = array_keys($this->_metadata);
        }
        return $this->_cols;
    }
288392
public function getColumns()
	{
		$return = $this->columns;

		try {
			$this->getParent();

			if (!$this->getSessionData('_grid_hidden_columns_manipulated', false)) {
				$columns_to_hide = [];

				foreach ($this->columns as $key => $column) {
					if ($column->getDefaultHide()) {
						$columns_to_hide[] = $key;
					}
				}

				if (!empty($columns_to_hide)) {
					$this->saveSessionData('_grid_hidden_columns', $columns_to_hide);
					$this->saveSessionData('_grid_hidden_columns_manipulated', true);
				}
			}

			$hidden_columns = $this->getSessionData('_grid_hidden_columns', []);

			foreach ($hidden_columns as $column) {
				if (!empty($this->columns[$column])) {
					$this->columns_visibility[$column] = [
						'visible' => false,
					];

					unset($return[$column]);
				}
			}

		} catch (DataGridHasToBeAttachedToPresenterComponentException $e) {
		}

		return $return;
	}
406428
protected function addCols(array $cols)
    {
        foreach ($cols as $key => $val) {
            if (is_int($key)) {
                $this->addCol($val);
            } else {
                $this->addCol($key, $val);
            }
        }
        return $this;
    }
352464
protected function buildColumnDispatch()
    {
        $this->columnDispatch = array();

        foreach ($this->getComponents() as $item) {
            if ($item instanceof GridField_ColumnProvider) {
                $columns = $item->getColumnsHandled($this);

                foreach ($columns as $column) {
                    $this->columnDispatch[$column][] = $item;
                }
            }
        }
    }
1152942
protected function columns()
    {
        $this->data    = $this->setData();
        $column_widths = $this->getColumnWidths();
        $output        = [];
        $count         = count(reset($this->data));

        for ($i = 0; $i < $count; $i++) {
            $output[] = $this->getRow($i, $column_widths);
        }

        return $output;
    }
758631
protected function buildTemplate()
    {
        $this->t_wrap->del('rows');
        $this->t_wrap->appendHTML('rows', '{rows}');

        for ($row = 1; $row <= $this->rows; $row++) {
            $this->t_row->del('column');

            for ($col = 1; $col <= $this->columns; $col++) {
                $this->t_col->set('Content', '{$r'.$row.'c'.$col.'}');

                $this->t_row->appendHTML('column', $this->t_col->render());
            }

            $this->t_wrap->appendHTML('rows', $this->t_row->render());
        }
        $this->t_wrap->appendHTML('rows', '{/rows}');
        $tmp = new Template($this->t_wrap->render());

        $this->template->template['rows#1'] = $tmp->template['rows#1'];

        $this->template->rebuildTags();
        $this->addClass($this->words[$this->columns].' column');
    }
922626
protected function createComponentUserList(): DataGrid
	{
		$grid = $this->dataGridFactory->create();

		$grid->setDataSource($this->orm->users->findAll());

		$grid->addToolbarButton('add', 'cms.user.add')
			->setIcon('plus');

		$grid->addColumnText('username', 'cms.user.username')
			->setSortable()
			->setFilterText();

		$grid->addColumnText('firstName', 'cms.user.firstName')
			->setSortable()
			->setFilterText();

		$grid->addColumnText('surname', 'cms.user.surname')
			->setSortable()
			->setFilterText();

		$grid->addColumnText('email', 'cms.user.email')
			->setSortable()
			->setFilterText();

		$grid->addColumnText('roles', 'cms.permissions.roles', 'roles.id')
			->setRenderer(function (User $user) {
				$obj = new Html;
				$delimiter = '';
				foreach ($user->roles as $role) {
					$link = Html::el('a');
					$link->href = $this->link('Permissions:editRolePermissions', ['id' => $role->id]);
					$link->addText($role->title);
					$obj->addHtml($delimiter . $link);
					$delimiter = ', ';
				}
				return $obj;
			})
			->setFilterSelect(['' => $this->translate('form.none')] + $this->orm->aclRoles->fetchPairs($this->user->isAllowed('dockbar.settings.permissions.superadmin', 'view')));

		$active = [
			'' => 'form.none',
			1 => 'default.active',
			0 => 'default.deactive'
		];
		$state = $grid->addColumnStatus('active', 'cms.user.state');
		$state->setFilterSelect($active)
			->setTranslateOptions();
		$state->addOption(1, 'default.active')
			->setClass('btn-success');
		$state->addOption(0, 'default.deactive')
			->setClass('btn-danger');
		$state->onChange[] = [$this, 'setState'];

		if ($this['tryUser']->isAllowed()) {
			$grid->addAction('tryUser', null, 'tryUser!')
				->addAttributes(['target' => '_blank'])
				->setIcon('user')
				->setTitle('cms.user.tryUser');
		}

		$grid->addAction('edit', null)
			->setIcon('pencil')
			->setTitle('cms.user.edit');

		$grid->addAction('changePassword', null)
			->setIcon('wrench')
			->setTitle('cms.user.changePassword');

		$grid->addAction('delete', null, 'delete!')
			->setIcon('trash')
			->setTitle('default.delete')
			->setClass('btn btn-xs btn-danger ajax')
			->setConfirm(function (User $user) {
				return $this->translate('default.confirmDelete', null, ['name' => $user->fullName]);
			});

		$grid->addGroupAction('default.activate')->onSelect[] = [$this, 'activateUsers'];
		$grid->addGroupAction('default.deactivate')->onSelect[] = [$this, 'deactivateUsers'];
		$grid->addGroupAction('default.delete')->onSelect[] = [$this, 'deleteUsers'];

		return $grid;
	}