How to disable pjax on a specific link inside of a GridView?

Hi, according to the docs:

You may disable pjax for a specific link inside the container by adding data-pjax="0" attribute to this link.


However, the “data-pjax” attribute is not being rendered by the Html::a helper for a simple link column in a GridView widget. This is my code:

    <?php Pjax::begin(); ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
                'value' => function ($data) {
                    return Html::a(Html::encode($data->name), ['view', 'id' => $data->id], ['data-pjax'=>0]);
    ]); ?>
    <?php Pjax::end(); ?>

Am I missing something? If I change the third argument of Html::a to be:


It renders the attribute properly, so I’m lost as to why it’s not rendering the required custom attribute to disable pjax on that link. In fact, no custom html tags are being rendered. Any ideas will be appreciated. Thanks!

The problem was:


because “the value is purified using HtmlPurifier to avoid XSS attacks”, so the data-pjax attribute was being filtered out. The solution was to use “raw” format to avoid any purification:


However, this will be insecure if some of the HTML comes from user input. In that case, perhaps making an exception for the data-pjax attribute (whitelisting) may be possible by configuring the HTMLPurifier helper, but in my case it was just a simple link so it’s solved for me. Hope it helps someone in the future.

1 Like