Krajee

Multiple Export Menus

Thankful to Krajee! BUY A COFFEEor to get more out of us.
An example showing multiple export menu widgets on the same page with different data providers. It also shows an use of 2 array data providers. Note you must set unique identifiers options['id'] for each export menu. By default this will be uniquely generated by the yii2-export extension anyway.

Tip

Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)

use kartik\export\ExportMenu;
use yii\data\ArrayDataProvider;
$dp1 = new ArrayDataProvider(['allModels' => [
    ['id' => 1, 'fruit' => 'Apples', 'quantity' => '100'],
    ['id' => 2, 'fruit' => 'Oranges', 'quantity' => '60'],
    ['id' => 3, 'fruit' => 'Bananas', 'quantity' => '160'],
    ['id' => 4, 'fruit' => 'Pineapples', 'quantity' => '90'],
    ['id' => 5, 'fruit' => 'Grapes', 'quantity' => '290'],
]]);
$dp2 = new ArrayDataProvider(['allModels' => [
    ['id' => 1, 'vegetable' => 'Potatoes', 'quantity' => '190'],
    ['id' => 2, 'vegetable' => 'Onions', 'quantity' => '300'],
    ['id' => 3, 'vegetable' => 'Carrots', 'quantity' => '20'],
    ['id' => 4, 'vegetable' => 'Beans', 'quantity' => '50'],
    ['id' => 5, 'vegetable' => 'Garlic', 'quantity' => '170'],
]]);
// First export menu for dataprovider no. 1 - fruits
echo ExportMenu::widget([
    'dataProvider' => $dp1,
    'columns' => ['id', 'fruit', 'quantity'],
    'options' => ['id'=>'expMenu1'], // optional to set but must be unique
    'target' => ExportMenu::TARGET_BLANK
]);
// Second export menu for dataprovider no. 2 - vegetables
echo ExportMenu::widget([
    'dataProvider' => $dp2,
    'columns' => ['id', 'vegetable', 'quantity'],
    'options' => ['id'=>'expMenu2'], // optional to set but must be unique
    'target' => ExportMenu::TARGET_BLANK
]);

Note

You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.

The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.

 
visitors to Krajee Yii2 Demos since 22-May-2017