Commit e8307085 by Qiang Xue

Merge pull request #2612 from tof06/master

Add an option to ignore pjax request on some links.
parents 4b20fdc7 078fdab6
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
// event - "click" jQuery.Event // event - "click" jQuery.Event
// options - pjax options // options - pjax options
// //
// If the click event target has 'data-pjax="0"' attribute, the event is ignored, and no pjax call is made.
//
// Examples // Examples
// //
// $(document).on('click', 'a', $.pjax.click) // $(document).on('click', 'a', $.pjax.click)
...@@ -61,6 +63,10 @@ ...@@ -61,6 +63,10 @@
var link = event.currentTarget var link = event.currentTarget
// Ignore links with data-pjax="0"
if ($(link).data('pjax')==0)
return
if (link.tagName.toUpperCase() !== 'A') if (link.tagName.toUpperCase() !== 'A')
throw "$.fn.pjax or $.pjax.click requires an anchor element" throw "$.fn.pjax or $.pjax.click requires an anchor element"
......
...@@ -88,6 +88,7 @@ class ActionColumn extends Column ...@@ -88,6 +88,7 @@ class ActionColumn extends Column
$this->buttons['view'] = function ($url, $model) { $this->buttons['view'] = function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [ return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('yii', 'View'), 'title' => Yii::t('yii', 'View'),
'data-pjax' => '0',
]); ]);
}; };
} }
...@@ -95,6 +96,7 @@ class ActionColumn extends Column ...@@ -95,6 +96,7 @@ class ActionColumn extends Column
$this->buttons['update'] = function ($url, $model) { $this->buttons['update'] = function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('yii', 'Update'), 'title' => Yii::t('yii', 'Update'),
'data-pjax' => '0',
]); ]);
}; };
} }
...@@ -104,6 +106,7 @@ class ActionColumn extends Column ...@@ -104,6 +106,7 @@ class ActionColumn extends Column
'title' => Yii::t('yii', 'Delete'), 'title' => Yii::t('yii', 'Delete'),
'data-confirm' => Yii::t('yii', 'Are you sure to delete this item?'), 'data-confirm' => Yii::t('yii', 'Are you sure to delete this item?'),
'data-method' => 'post', 'data-method' => 'post',
'data-pjax' => '0',
]); ]);
}; };
} }
......
...@@ -25,6 +25,8 @@ use yii\web\Response; ...@@ -25,6 +25,8 @@ use yii\web\Response;
* You may configure [[linkSelector]] to specify which links should trigger pjax, and configure [[formSelector]] * You may configure [[linkSelector]] to specify which links should trigger pjax, and configure [[formSelector]]
* to specify which form submission may trigger pjax. * to specify which form submission may trigger pjax.
* *
* You may disable pjax for a specific link inside the container by adding `data-pjax="0"` attribute to this link.
*
* The following example shows how to use Pjax with the [[\yii\gridview\GridView]] widget so that the grid pagination, * The following example shows how to use Pjax with the [[\yii\gridview\GridView]] widget so that the grid pagination,
* sorting and filtering can be done via pjax: * sorting and filtering can be done via pjax:
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment