Krajee

Column Selector - Case 2

Thankful to Krajee! BUY A COFFEEor to get more out of us.
Extension of column selector case 1 to preset your column selections on load (let's say only ID, Name, Author Name, Color, & Publish Date is preselected). Let's add one more column (Color) to the hiddenColumns as well (though hidden from selection, this will still be displayed on export as it is set in selectedColumns). Set noExportColumns to hide from export and the dropdown (e.g. let's not export the Status column). In addition customize the column labels displayed in the column selector (e.g. change Buy Amount and Sell Amount labels).

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)


Showing 1-5 of 20 items.
#IDNameAuthorColorPublish DateStatusBuy Amount ($)Sell Amount ($)Actions
11001The Great GatsbyF. Scott Fitzgeraldblue2016-04-01Active209.00300.00
21002The Grapes of WrathJohn Steinbeckred1995-07-18Active104.00155.50
31003Nineteen Eighty-FourGeorge Orwellorange1984-02-27Active79.0098.50
41004UlyssesJames Joycegreen1974-12-10Inactive69.0098.50
51005LolitaVladimir Nabokovpink2004-05-09Active58.0085.50
use kartik\export\ExportMenu;
use kartik\grid\GridView;
use kartik\helpers\Html;
echo ExportMenu::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'selectedColumns'=> [1, 2, 3, 4, 5],  // Col seq 2 to 6
    'columnSelector' => [
        7 => 'Amount Bought', // Buy Amount
        8 => 'Amount Sold' ,  // Sell Amount
    ],
    'columnSelectorOptions'=>[
        'label' => 'Cols...',
    ],
    'hiddenColumns'=>[0, 4, 9], // SerialColumn, Color, & ActionColumn
    'disabledColumns'=>[1, 2], // ID & Name
    'noExportColumns'=>[6], // Status
    'dropdownOptions' => [
        'label' => 'Export All',
        'class' => 'btn btn-outline-secondary btn-default'
    ]
]) . "<hr>\n".
GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'export' => []
]);
$gridColumns = [
    ['class' => 'kartik\grid\SerialColumn'],
    'id',
    'name',
    [
        'attribute'=>'author_id',
        'label'=>'Author',
        'vAlign'=>'middle',
        'width'=>'190px',
        'value'=>function ($model, $key, $index, $widget) { 
            return Html::a($model->author->name, '#', []);
        },
        'format'=>'raw'
    ],
    'color',
    'publish_date',
    'status',
    ['attribute'=>'buy_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'],
    ['attribute'=>'sell_amount','format'=>['decimal',2], 'hAlign'=>'right', 'width'=>'110px'],
    ['class' => 'kartik\grid\ActionColumn', 'urlCreator'=>function(){return '#';}]
];

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