Export to csv

Info Default are column names from columns which implemented Mesour\DataGrid\Column\IExportable

Method enableExport

  • $cacheDir writable dir
  • $fileName specify dowloaded file name
$grid->enableExport($cacheDir, $fileName = NULL);

Change csv delimiter

Info Default is ,
$export = $grid->enableExport($cacheDir, $fileName = NULL);

$export->setDelimiter(';');

Usage

Important You have to use method create() in controller. It will return Mesour\DataGrid\Renderer\IGridRenderer and in template use render() on this renderer. Because Mesour\DataGrid\Extensions\Export\ExportExtension set some headers.
$mesourApp = //instance Mesour\Components\Application\IApplication
$source = //some <a href="http://components.mesour.com/version3/component/sources/" target="_blank">data source</a> or two-dimensional array

$grid = new Mesour\UI\DataGrid('exportDataGrid', $mesourApp);

$grid->setSource($source);

//! here enable sortable extension
$grid->enableExport(__DIR__ . '/../../../temp/cache', 'grid_values.csv');

$grid->addText('name', 'Name');

$grid->addText('surname', 'Surname');

$grid->addText('email', 'E-mail');

//! in controller (presenter)
$this->template->gridRenderer = $grid->create(); 

//! in template
$gridRenderer->render();

Demo


NameSurnameE-mail
JohnDoejohn.doe@test.xx
PeterLarsonpeter.larson@test.xx
ClaudeGravesclaude.graves@test.xx
StuartNormanstuart.norman@test.xx
KathyArnoldkathy.arnold@test.xx
JanWilsonjan.wilson@test.xx
AlbertaEricksonalberta.erickson@test.xx
AdaWellsada.wells@test.xx
EthelFigueroaethel.figueroa@test.xx
IanGoodwinian.goodwin@test.xx
FrancisHayesfrancis.hayes@test.xx
ErmaBurnserma.burns@test.xx
KristinaJenkinskristina.jenkins@test.xx
VirgilHuntvirgil.hunt@test.xx
MaxMartinmax.martin@test.xx
MelodyManningmelody.manning@test.xx
CatherineToddcatherine.todd@test.xx
DouglasStanleydouglas.stanley@test.xx
PattiDiazpatti.diaz@test.xx
JohnPettersonjohn.petterson@test.xx
Export