/** * {@inheritDoc} */ public function visitMetadata(DatagridConfiguration $config, MetadataObject $data) { $multisort = $config->offsetGetByPath(Configuration::MULTISORT_PATH, false); $sorters = $this->getSorters($config); $proceed = []; foreach ($data->offsetGetOr('columns', []) as $key => $column) { if (isset($column['name']) && isset($sorters[$column['name']])) { $data->offsetSetByPath(sprintf('[columns][%s][sortable]', $key), true); $proceed[] = $column['name']; } } $extraSorters = array_diff(array_keys($sorters), $proceed); if (count($extraSorters)) { throw new LogicException(sprintf('Could not found column(s) "%s" for sorting', implode(', ', $extraSorters))); } $data->offsetAddToArray(MetadataObject::OPTIONS_KEY, ['multipleSorting' => $multisort]); $sortersState = $this->getSortersState($config, $data); $initialSortersState = $this->getSortersState($config, $data, false); $data->offsetAddToArray('initialState', ['sorters' => $initialSortersState]); $data->offsetAddToArray('state', ['sorters' => $sortersState]); }
/** * {@inheritdoc} */ public function visitMetadata(DatagridConfiguration $config, MetadataObject $data) { $data->offsetSetByPath('mode', $this->getMode($config)); }
/** * Set default columns order to Metadata * Fill order for not configured fields * * @param DatagridConfiguration $config * @param MetadataObject $data */ protected function setColumnsOrder(DatagridConfiguration $config, MetadataObject $data) { $columnsOrdered = $this->getColumnsWithOrder($config); $columns = $data->offsetGetOr(self::COLUMNS_PATH, []); foreach ($columns as $key => $column) { if (isset($column['name'])) { $columnName = $column['name']; if (isset($columnsOrdered[$columnName])) { if (isset($columnsOrdered[$columnName]['order'])) { $order = $columnsOrdered[$columnName]['order']; $data->offsetSetByPath(sprintf('[columns][%s][order]', $key), $order); } if (isset($columnsOrdered[$columnName]['renderable'])) { $renderable = $columnsOrdered[$columnName]['renderable']; $data->offsetSetByPath(sprintf('[columns][%s][renderable]', $key), $renderable); } } } } }