From 4239caf9eba9b01901f75ba69fbe2e9ff3e2d4bb Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 15 Jul 2017 12:18:11 +1000 Subject: [PATCH] Enable searching via config Only the ServerEventDataSource supports this for now. This is purely to satisfy https://github.com/rainlab/translate-plugin/pull/272 Clean up and fix net spam --- modules/backend/widgets/Table.php | 1 + modules/backend/widgets/table/assets/js/build-min.js | 5 +++-- .../widgets/table/assets/js/table.helper.search.js | 6 +++++- modules/backend/widgets/table/partials/_table.htm | 9 +-------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/backend/widgets/Table.php b/modules/backend/widgets/Table.php index e79fc7376..669d7327e 100644 --- a/modules/backend/widgets/Table.php +++ b/modules/backend/widgets/Table.php @@ -121,6 +121,7 @@ class Table extends WidgetBase $this->vars['recordsPerPage'] = $this->getConfig('recordsPerPage', false) ?: 'false'; $this->vars['postbackHandlerName'] = $this->getConfig('postbackHandlerName', 'onSave'); + $this->vars['searching'] = $this->getConfig('searching', true); $this->vars['adding'] = $this->getConfig('adding', true); $this->vars['deleting'] = $this->getConfig('deleting', true); $this->vars['toolbar'] = $this->getConfig('toolbar', true); diff --git a/modules/backend/widgets/table/assets/js/build-min.js b/modules/backend/widgets/table/assets/js/build-min.js index 9777bd728..c952a6c34 100644 --- a/modules/backend/widgets/table/assets/js/build-min.js +++ b/modules/backend/widgets/table/assets/js/build-min.js @@ -569,8 +569,9 @@ this.searchInput=$('.table-search-input',this.searchForm).get(0)}} Search.prototype.getQuery=function(){return $.trim(this.activeQuery)} Search.prototype.hasQuery=function(){return this.searchEnabled()&&$.trim(this.activeQuery).length>0} Search.prototype.searchEnabled=function(){return this.tableObj.options.searching} -Search.prototype.performSearch=function(query,onSuccess){this.activeQuery=query -this.tableObj.updateDataTable(onSuccess)} +Search.prototype.performSearch=function(query,onSuccess){var isDirty=this.activeQuery!=query +this.activeQuery=query +if(isDirty){this.tableObj.updateDataTable(onSuccess)}} Search.prototype.onKeydown=function(ev){if(ev.keyCode==9){this.onClick(ev) return} if(!this.isActive){return} diff --git a/modules/backend/widgets/table/assets/js/table.helper.search.js b/modules/backend/widgets/table/assets/js/table.helper.search.js index 0f3baa130..16501a24b 100644 --- a/modules/backend/widgets/table/assets/js/table.helper.search.js +++ b/modules/backend/widgets/table/assets/js/table.helper.search.js @@ -74,9 +74,13 @@ } Search.prototype.performSearch = function(query, onSuccess) { + var isDirty = this.activeQuery != query + this.activeQuery = query - this.tableObj.updateDataTable(onSuccess) + if (isDirty) { + this.tableObj.updateDataTable(onSuccess) + } } // EVENT HANDLERS diff --git a/modules/backend/widgets/table/partials/_table.htm b/modules/backend/widgets/table/partials/_table.htm index 7d0572922..8d46c5b40 100644 --- a/modules/backend/widgets/table/partials/_table.htm +++ b/modules/backend/widgets/table/partials/_table.htm @@ -8,6 +8,7 @@ data-field-name="fieldName) ?>" data-postback-handler-name="" data-adding="" + data-searching="" data-deleting="" data-toolbar="" data-height="" @@ -34,14 +35,6 @@