-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: New section: Export functionality #1550
Comments
to customize the format you need to overwrite those 3 methods: /**
* {@inheritdoc}
*/
public function getExportFormats()
{
return array(
'json', 'xml', 'csv', 'xls'
);
}
/**
* @return array
*/
public function getExportFields()
{
return $this->getModelManager()->getExportFields($this->getClass());
}
/**
* @return
*/
public function getDataSourceIterator()
{
$datagrid = $this->getDatagrid();
$datagrid->buildPager();
return $this->getModelManager()->getDataSourceIterator($datagrid, $this->getExportFields());
} If you want a deeper control on how export are handled, you need to review the CrudController and the |
But for example: public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null)
{
$datagrid->buildPager();
$query = $datagrid->getQuery();
$query->select('DISTINCT ' . $query->getRootAlias());
$query->setFirstResult($firstResult);
$query->setMaxResults($maxResult);
if ($query instanceof ProxyQueryInterface) {
$query->addOrderBy($query->getSortBy(), $query->getSortOrder());
$query = $query->getQuery();
}
return new DoctrineORMQuerySourceIterator($query, $fields);
} |
👍 |
👍 - yeap, docs definitely need update - even this time of explanation like @rande wrote here whould be great over there. It took ma a while to figure this out. I made my custom Writers, custom export service and custom functions to be able to export proper headers ( with translations) and the same columns as visible in datagrid on sonata admin list but it really took me really long while to figure out that data format is set inside DoctrineORMQuerySourceIterator.php Whole export functionality would benefit from some update, not only from new docs :) It's quite strange that it exports all columns from entity with column names instead of labels. Not to mention this headers are not translated in any way and that linked entities are not exported at all by default. I try to get involved in fixing docs a bit when I finish my project. |
@krewetka Any changes that you could add some info to the docs about Exports or show examples from your project? I am very interested in that, if I manage to learn I can add the docs myself I just need to know where to start and maybe few examples. |
@krewetka, it's quite an obscure feature, but export headers (labels) can be overwritten by using keys in getExportFields method. It can even be translated!! I don't know where to modify Bundle doc by including this information, but you can code something like the following: public function getExportFields()
{
return array(
'field label 1' => 'field1',
$this->trans('field label 2') => 'field2',
'field label 3' => 'field3',
...
);
} |
@rodrigobb actually looking at the output of |
3 years later is not to late I guess :P see #4029 |
Override
It works fine. Other, your also can override |
When using SonataAdmin your list view shows options to export the data... but there's no mention of this in the current docs. What we need is a new chapter which covers:
I'm new to SonataAdmin so I don't know what's possible with exports. I look forward to reading your docs to fill in this gap in my knowledge!
You can either make a ready-to-merge rst file or send me a hyperlink, document file, or detailed comment which I will then reformat and merge into the documentation.
See #1519 for details about the co-ordination of new documentation entries and other ways to contact me.
The text was updated successfully, but these errors were encountered: