0

i'm trying to export a grid i create with the object MVCgrid.

I found out that i can add the the current page the object 'MVCGrid_Export' instead of the object 'MVCGrid'that provides the export buttons and functionalities.

By the way i got an error during the export :

"Fatal error: Call to a member function getField() on a non-object in ..\agiletoolkit\atk4-addons\misc\lib\Export.php on line 42"

At that line, "$b[] = $this->__getHeaderModel()->getField($a)->caption();", i discovered that the result of "$this->_getHeaderModel()" is a string of the model i want to export, and not the object of that model , that is the item i need.

This is the code of my page:

class page_resultsShow extends Page {
function initMainPage() {
    $p = $this;
    $gr = $this->add('MVCGrid_Export');
    $gr->setModel('results',array('name','budget','bestapplicants'));

    $gr->addColumnMVC('name');
    $gr->addFormatter('name','link');
    $gr->addQuickSearch(array('name'));
    $gr->addPaginator(20); 
}

//details...
function page_details() {
    ... some code..
}

function defaultTemplate(){
    return array('page/results');
}

}

I suppose i need to add some informations to explain to the grid the model that is handling , but i didn't find how!!

Thank you for the help

1 Answers1

0

We have pushed updated export module for 4.2

Please, update atk4-addons and atk4 to make sure you are on master branch (which is now 4.2).

syntax is a bit different now, as Export now acts as controller.

class page_index extends Page {
    function init(){
        parent::init();
        $c=$this->add("Grid");
        $c->setModel("A");
        $c->addPaginator(1);
        $c->add("Export");

        $c=$this->add("CRUD");
        $c->setModel("A");
        if ($c->grid){
            $c->grid->addPaginator(1);
        }
        $c->add("Export");
    }
}

From email to atk4 group:

// let's say you have grid

$export = $grid->add("Export");

// this would add export xls & export csv buttons to your grid

// if you have crud:

$export = $crud->add("Export");

// this would add export xls & export csv buttons to your grid

Now, you can easily create new "Parsers", by creating

Export_Parser_Xyz class.

then just add it to your export:

$export->add("Export_Parser_Xyz");

very important update is that it now uses dq after it has been altered by paginators, filters etc. so that it would export exactly what is displayed. Optional, is limit which by default is being removed, but can be controlled on a parser level.

this would automatically add button to grid/crud and handle data flow from respective grid/crud data source.

N.B.!

Export works only with dq based Grid and, if model is defined, attempts to load captions from model's field definitions. PDF parser is left out at this point, as it was very specific and required specific 3rd party software.

Should you want to have old Export module follow instructions in lib/Export.php to enable compatibility mode.


jancha
  • 4,916
  • 1
  • 24
  • 39