2

我为每个表都有一个 ActionColumn。我需要order => ORDER_FIX_RIGHT为 ActionColumn 添加每个表。如何order在我的 DynaGridViewAdvanced 中添加密钥?

我试着写:

protected function applyColumns()
    {
        $columns = [];
        $newColumns = [];
        foreach ($this->columns as $column) {
            $order = ArrayHelper::getValue($column, 'order', self::ORDER_MIDDLE);
            
            if ($order == self::ORDER_FIX_LEFT) {
                $newColumns[] = $column;
                unset($column['order']);
                $columns[] = $column;
            }
        }
        
        foreach ($this->_visibleKeys as $key) {
            if (empty($this->_columns[$key])) {
                continue;
            }
            $column = $this->_columns[$key];
            $newColumns[] = $column;
            if (isset($column['order'])) {
                unset($column['order']);
            }
            if (isset($column['visible'])) {
                unset($column['visible']);
            }
            $columns[] = $column;
        }
        
        foreach ($this->columns as $column) {
            $order = ArrayHelper::getValue($column, 'order', self::ORDER_MIDDLE);
            $isActionColumn = is_array($column) && array_key_exists('class', $column) && (new $column['class']) instanceof ActionColumn;
            
            if ($order == self::ORDER_FIX_RIGHT) {
                $newColumns[] = $column;
                unset($column['order']);
                $columns[] = $column;
            }
            
            if ($isActionColumn) {
                $column['order'] = self::ORDER_FIX_RIGHT;
                $newColumns[] = $column;
                unset($column['order']);
                $columns[] = $column;
            }
        }
        
        $this->columns = $newColumns;
        $this->gridOptions['columns'] = $columns;
    }

但它是第二列。如果我写:

protected function prepareColumns()
    {
        $this->_columns = $this->columns;
        $columns = [];
        
        foreach ($this->columns as $column) {
            $isActionColumn = is_array($column) && array_key_exists('class', $column) && (new $column['class']) instanceof ActionColumn;
            
            if (is_array($column) && !$isActionColumn) {
                unset($column['order']);
            }
            
            if ($isActionColumn) {
                $column['order'] = $this->actionColumnsPosition;
            }
            
            $columns[] = $column;
        }
        
        
        $this->gridOptions['columns'] = $columns;
    }

一切正常,但是当我在列中更改一些内容时,我有以下例外:

设置未知属性 ...ActionColumn::order

4

1 回答 1

0

完毕。我setDefaultOrderToActionColumns用内容创建了方法:

private function setDefaultOrderToActionColumns() {
    foreach ($this->columns as &$column) {
        $columnTypeIsAction = is_array($column) && array_key_exists('class', $column) && (new $column['class']) instanceof ActionColumn;
        
        if ($columnTypeIsAction) {
            $column['order'] = $this->actionColumnsPosition;
        }
    }
}

并在重新定义的方法中调用它run

public function run() {
    ...
    $this->setDefaultOrderToActionColumns();
}
于 2020-06-22T09:14:53.370 回答