Q:

target _blank in HTML::a not working yii2

I am using below peice of code.
[
            'attribute' => 'Application',
            'format' => 'html',
            'value' => function ($dataProvider) {
                $student_username = $dataProvider->student_username;
                return Html::a('Print', Url::toRoute(['/coordinatorpanel/print-form', 'student_username' => $student_username]),
                    ['target' => '_blank', 'class' => 'btn btn-success center-block']);
            },
        ]

HTML OUTPUT : 
<a class="btn btn-success center-block" href="/nse/frontend/web/index.php?r=coordinatorpanel%2Fprint-form&amp;student_username=COR39690113" target="_blank">

But, when I click on the link, I am not navigated to new tab, the request is processed in same Tab. I tried this on both 'Mozilla' and 'Chrome'.
Any help would be deeply rewared :)

A:

Disable Pjax in gridview. In my case I wanted to display an image in a new window and it was coming up as garbled characters in the grid instead. 
'format' => "raw",
'value' => function ($d) {
     return Html::a($d->image_filename, '/'.$d->imagePath(),['target'=>'_blank', 'data-pjax'=>"0"] );
    },

A:

Try to change your code like below
[
        'attribute' => 'Application',
        'format' => 'raw',
        'value' => function ($dataProvider) {
            $student_username = $dataProvider->student_username;
            return Html::a('Print', Url::toRoute(['/coordinatorpanel/print-form', 'student_username' => $student_username]),
                ['target' => '_blank', 'class' => 'btn btn-success center-block']);
        },
    ]

Here it used 'format' => 'raw' to avoid formatting.

A:

I had to go other way round to run code properly.
You can click here for reference
Below is the piece of code that I modified and worked for me. I had to set 'onclick' event and set href as empty.
[
    'attribute' => 'Application',
    'format' => 'raw',
    'value' => function ($dataProvider) {
        $student_username = $dataProvider->student_username;
        return Html::a('Print', '',
            ['onclick' => "window.open ('".Url::toRoute(['/coordinatorpanel/print-form', 
                          'student_username' => $student_username])."'); return false", 
             'class' => 'btn btn-success center-block']);
    },
],

