Ublaboo\DataGrid – download souboru vytvoreneho podle group action

Honza.Mottl
Člen | 104
+
0
-

Ahoj, pouzivam Ublaboo\DataGrid group action pro vyber xml souboru objednavek. Podle vybranych ids si najdu xml soubory a vytvorim si zip. Ted bych potreboval vytvoreny zip poslat na klienta. Da se nejak sikovne zapojit do Ublaboo\DataGrid resp. do jeho klientske casti? Diky

Jinak pri filtrovani v gridu se mi prestalo fungovat zaskrtavani. Zapnul jsem happy components a rozjelo se to.
Pokud ale zmenim filtry, tak musim dat reload stranky, aby zaskrtavani zase fungovalo.

public function createComponentObjednavkaxmlDatagrid($name) {
    $grid = new DataGrid($this, $name);

	// ....

    $grid->addGroupAction('Stáhnout xml')->onSelect[] = [$this, 'downloadXml'];
    $grid->useHappyComponents(true);
}

public function downloadXml(array $ids)
{
    $outputZipPath = $this->prilohaManager->getZippedObjXml($logicalOutputName, $this->context->parameters['documents_path'], $ids);

    if (!empty($outputZipPath)) {
        $this->sendResponse(new \Nette\Application\Responses\FileResponse($outputZipPath, $logicalOutputName, ''));
    }

    if ($this->isAjax()) {
        $this['groupActionsGrid']->reload();
    } else {
        $this->redirect('this');
    }
}
Honza.Mottl
Člen | 104
+
0
-

Zatim me napadlo reseni:

  • poslat na klienta snippet se jmenem zip souboru
  • odchytit snippet, zjistit jmeno souboru a poslat servrevu pozadavek na download
<?php
    public function downloadXml(array $ids)
    {
        $outputZipPath = $this->prilohaManager->getZippedObjXml($logicalOutputName, $this->context->parameters['documents_path'], $ids);

        if (!empty($outputZipPath)) {
            $this->template->filePath = $outputZipPath;
            $this->template->logicalName = $logicalOutputName;
            $this->redrawControl('downloadFile');
        }

        if ($this->isAjax()) {
            $this['groupActionsGrid']->reload();
        } else {
            $this->redirect('this');
        }
    }
?>
<?php
{block content}
    <div class="table-responsive">
        {control objednavkaxmlDatagrid}
    </div>
    {snippet downloadFile}
        <input type="hidden" filePath="{$filePath}" logicalName="{$logicalName}" id="fileName">
    {/snippet}
{/block}
?>
<script>
        $.nette.ext('datagrid.handling', {
            success: function(payload) {
                if (payload && payload.snippets) {
                    Object.keys(payload.snippets).forEach(function(snippet,index) {
                        if (snippet.indexOf('downloadFile') !== -1) {
                            /*
                                spustit ajaxovy pozadavek na download

                             */
                        }
                    });
                }
            }});
</script>