Reinitialize Kartik plugins after Pjax with pjaxContainerId

Quick and easy self note: when using Kartik plugins for Yii2, and including them in a Pjax container, some may need to be reinitialized.

Without getting crazy, Kartik already thought about this by providing a common property to all his widgets: pjaxContainerId. As the documentation states:

container ID if applicable inside which the widget will be rendered. If this is set, the widget will automatically reinitialize on pjax render completion.

So if you set that value to the ID of the pjax container, when the content is loaded the widget will be initialized correctly.

For example:

    'id' => 'form-pjax',

echo $form->field($model, 'data_lettura_iniziale')->widget(DateControl::className(), [
    'ajaxConversion' => false,
    'pjaxContainerId' => 'form-pjax', // No need to prepend #
    'pluginOptions' => [
        'autoclose' => true,


Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Solve : *
27 × 24 =

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.