mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Fixes #16365: Added $filterOnFocusOut option for GridView
This commit is contained in:

committed by
Alexander Makarov

parent
a5c8b215b3
commit
80d0c2b05a
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.16 under development
|
2.0.16 under development
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
- Enh #16365: Added $filterOnFocusOut option for GridView (s1lver)
|
||||||
- Enh #14289: Added `yii\db\Command::executeResetSequence()` to work with Oracle (CedricYii)
|
- Enh #14289: Added `yii\db\Command::executeResetSequence()` to work with Oracle (CedricYii)
|
||||||
- Enh #9133: Added `yii\behaviors\OptimisticLockBehavior` (tunecino)
|
- Enh #9133: Added `yii\behaviors\OptimisticLockBehavior` (tunecino)
|
||||||
- Bug #16104: Fixed `yii\db\pgsql\QueryBuilder::dropIndex()` to prepend index name with schema name (wapmorgan)
|
- Bug #16104: Fixed `yii\db\pgsql\QueryBuilder::dropIndex()` to prepend index name with schema name (wapmorgan)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
if (methods[method]) {
|
if (methods[method]) {
|
||||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||||
} else if (typeof method === 'object' || !method) {
|
} else if (typeof method === 'object' || !method) {
|
||||||
return methods.init.apply(this, arguments);
|
return methods.init.apply(this, arguments);
|
||||||
} else {
|
} else {
|
||||||
$.error('Method ' + method + ' does not exist in jQuery.yiiGridView');
|
$.error('Method ' + method + ' does not exist in jQuery.yiiGridView');
|
||||||
return false;
|
return false;
|
||||||
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
filterUrl: undefined,
|
filterUrl: undefined,
|
||||||
filterSelector: undefined
|
filterSelector: undefined,
|
||||||
|
filterOnFocusOut: true
|
||||||
};
|
};
|
||||||
|
|
||||||
var gridData = {};
|
var gridData = {};
|
||||||
@ -82,6 +83,9 @@
|
|||||||
var $e = $(this);
|
var $e = $(this);
|
||||||
var settings = $.extend({}, defaults, options || {});
|
var settings = $.extend({}, defaults, options || {});
|
||||||
var id = $e.attr('id');
|
var id = $e.attr('id');
|
||||||
|
if (!settings.filterOnFocusOut) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (gridData[id] === undefined) {
|
if (gridData[id] === undefined) {
|
||||||
gridData[id] = {};
|
gridData[id] = {};
|
||||||
}
|
}
|
||||||
|
@ -248,6 +248,11 @@ class GridView extends BaseListView
|
|||||||
* This is mainly used by [[Html::error()]] when rendering an error message next to every filter input field.
|
* This is mainly used by [[Html::error()]] when rendering an error message next to every filter input field.
|
||||||
*/
|
*/
|
||||||
public $filterErrorOptions = ['class' => 'help-block'];
|
public $filterErrorOptions = ['class' => 'help-block'];
|
||||||
|
/**
|
||||||
|
* @var bool whatever to apply filters on losing focus. Leaves an ability to manage filters via yiiGridView JS
|
||||||
|
* @since 2.0.16
|
||||||
|
*/
|
||||||
|
public $filterOnFocusOut = true;
|
||||||
/**
|
/**
|
||||||
* @var string the layout that determines how different sections of the grid view should be organized.
|
* @var string the layout that determines how different sections of the grid view should be organized.
|
||||||
* The following tokens will be replaced with the corresponding section contents:
|
* The following tokens will be replaced with the corresponding section contents:
|
||||||
@ -288,10 +293,10 @@ class GridView extends BaseListView
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$id = $this->options['id'];
|
|
||||||
$options = Json::htmlEncode($this->getClientOptions());
|
|
||||||
$view = $this->getView();
|
$view = $this->getView();
|
||||||
GridViewAsset::register($view);
|
GridViewAsset::register($view);
|
||||||
|
$id = $this->options['id'];
|
||||||
|
$options = Json::htmlEncode(array_merge($this->getClientOptions(), ['filterOnFocusOut' => $this->filterOnFocusOut]));
|
||||||
$view->registerJs("jQuery('#$id').yiiGridView($options);");
|
$view->registerJs("jQuery('#$id').yiiGridView($options);");
|
||||||
parent::run();
|
parent::run();
|
||||||
}
|
}
|
||||||
@ -360,7 +365,7 @@ class GridView extends BaseListView
|
|||||||
$tableFooterAfterBody = $this->renderTableFooter();
|
$tableFooterAfterBody = $this->renderTableFooter();
|
||||||
} else {
|
} else {
|
||||||
$tableFooter = $this->renderTableFooter();
|
$tableFooter = $this->renderTableFooter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = array_filter([
|
$content = array_filter([
|
||||||
|
@ -14,11 +14,13 @@ describe('yii.gridView', function () {
|
|||||||
var $gridView;
|
var $gridView;
|
||||||
var settings = {
|
var settings = {
|
||||||
filterUrl: '/posts/index',
|
filterUrl: '/posts/index',
|
||||||
filterSelector: '#w0-filters input, #w0-filters select'
|
filterSelector: '#w0-filters input, #w0-filters select',
|
||||||
|
filterOnFocusOut: true
|
||||||
};
|
};
|
||||||
var commonSettings = {
|
var commonSettings = {
|
||||||
filterUrl: '/posts/index',
|
filterUrl: '/posts/index',
|
||||||
filterSelector: '#w-common-filters input, #w-common-filters select'
|
filterSelector: '#w-common-filters input, #w-common-filters select',
|
||||||
|
filterOnFocusOut: true
|
||||||
};
|
};
|
||||||
var $textInput;
|
var $textInput;
|
||||||
var $select;
|
var $select;
|
||||||
@ -143,7 +145,8 @@ describe('yii.gridView', function () {
|
|||||||
describe('init', function () {
|
describe('init', function () {
|
||||||
var customSettings = {
|
var customSettings = {
|
||||||
filterUrl: '/posts/filter',
|
filterUrl: '/posts/filter',
|
||||||
filterSelector: '#w-common-filters input'
|
filterSelector: '#w-common-filters input',
|
||||||
|
filterOnFocusOut: true
|
||||||
};
|
};
|
||||||
|
|
||||||
withData({
|
withData({
|
||||||
|
Reference in New Issue
Block a user