Bug exporting table view

GC Enterprise v3.0.13
mySql 8 DB

What I want to do is to show some data on a webpage but when exporting into xls add more data from other tables.
This is a simplified example of what I’m trying to do

Table A
columns A, B, C, D

MySQL View V
columns A, B, C, D from table A
columns E, F, G from table B

        $current_state = $crud->getState();

        if ( ($current_state == 'Export') || ($current_state == 'ExportPdf') || ($current_state == 'Print') ) {
            $crud->setTable('mysql_view_v');
            $field_list = array('A','B','C','D','E','F','G');
            $crud->setPrimaryKey('id','mysql_view_v');
        } else {
            $crud->setTable('table_a');
            $field_list = array('A','B','C','D');
        }

        $crud->columns($field_list);

The problem is that in the mysql_view export I’ve got only the fields that are coming from table_a (so in this example A, B, C, D and not E, F, G)

If just for testing I change my code and in the main page I show a random table_b with fields completely different from the view, the export of the view is correct

         } else {
            $crud->setTable('table_b');
            $field_list = array('X','Y','Z');
        }

the same page worked fine on GCE 2.x

thanks

Hello @Phil ,

Yes currently at the export level we are also sending the visible columns which we wasn’t sending before (on version 2). If you want to bypass this you will need to use replaceState instead. More specifically you can create a custom state that will look like this:

<?php
use GroceryCrud\Core\State\ExportState;
use GroceryCrud\Core\State\StateInterface;

class CustomExportState extends ExportState implements StateInterface {
    public function getStateParameters() {
        $stateParameters = parent::getStateParameters();

        $stateParameters->visible_columns = null;

        return $stateParameters;
    }
}

and add it to your code like this:

// Don't forget to include the file at the top
include('CustomExportState.php');
...

$exportState = new CustomExportState($crud);
$crud->replaceState('Export', $exportState);

The above code will replace the default Export state and instead always having the visible_columns = null. That means that it will show all the columns in export and you will have the desired results.

Regards
Johnny

1 Like

thank you, will try that!