From 10ec5d517ebee4bffaf68874bbe383ee4a9d1d38 Mon Sep 17 00:00:00 2001 From: Wangliangyu Date: Mon, 3 Dec 2018 15:45:47 +0800 Subject: [PATCH] Update table header checkbox after searching Now, the table header checkbox has no releationship with the searching on page by javasricpt. This will cause two situations: - The table header checkbox is checked and delete button is enable when there is nothing under table. - The table header checkbox is not checked when all rows filtered out are checked. This commit will update the table header checkbox after searching on page side, and fix the above bug suitable. Change-Id: Ic290a67c7c85644bdedc80930c7d5be772fabde0 Closes-Bug: #1806342 --- horizon/static/horizon/js/horizon.tables.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/horizon/static/horizon/js/horizon.tables.js b/horizon/static/horizon/js/horizon.tables.js index 6796072f20..5efc13f926 100644 --- a/horizon/static/horizon/js/horizon.tables.js +++ b/horizon/static/horizon/js/horizon.tables.js @@ -597,6 +597,20 @@ horizon.datatables.add_table_checkboxes = function($parent) { }); }; +horizon.datatables.update_header_checkbox = function(table) { + var $multi_select_checkbox = table.find('.multi-select-header'); + + var $checkboxes = table.find('tbody tr:visible .table-row-multi-select'); + if ($checkboxes.length == 0) { + $multi_select_checkbox.prop('checked', false); + $multi_select_checkbox.attr('disabled', true); + } else { + $multi_select_checkbox.removeAttr('disabled'); + var not_checked = $checkboxes.not(':checked').length; + $multi_select_checkbox.prop('checked', not_checked == 0); + } +}; + horizon.datatables.set_table_query_filter = function (parent) { horizon.datatables.qs = {}; $(parent).find('table').each(function (index, elm) { @@ -634,6 +648,7 @@ horizon.datatables.set_table_query_filter = function (parent) { horizon.datatables.update_footer_count(table); horizon.datatables.add_no_results_row(table); horizon.datatables.fix_row_striping(table); + horizon.datatables.update_header_checkbox(table); }, prepareQuery: function (val) { return new RegExp(horizon.string.escapeRegex(val), "i");