diff --git a/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js b/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js index ff073dade..85a246f67 100644 --- a/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js +++ b/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js @@ -30,8 +30,9 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) { _renderView: function () { var self = this; - // IMPORTANT: Don't reset search state, just preserve it - var hasActiveSearch = this._search && this._search.value; + // Store search state before render + var searchValue = this._search ? this._search.value : ''; + var hasActiveSearch = searchValue && searchValue.length > 0; return this._super.apply(this, arguments).then(function () { // Add search box if needed @@ -43,15 +44,16 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) { self._addSearchBox(); } - // Always restore search state after render + // Always restore search UI self._restoreSearchUI(); - // If we have an active search, apply the filter - if (hasActiveSearch && self._search.filteredIds) { - // Apply filter after DOM is ready + // If we had an active search, re-apply it after a short delay + if (hasActiveSearch) { setTimeout(function() { - self._reapplySearchFilter(); - }, 0); + if (self._search && self._search.value) { + self._performSearch(self._search.value); + } + }, 100); } } }); @@ -115,21 +117,6 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) { } }, - /** - * Reapply search filter after re-render - */ - _reapplySearchFilter: function() { - if (!this._search || !this._search.filteredIds) return; - - // If we have all filtered records, update the view - if (this._search.allFilteredRecords) { - this._updateViewWithFilteredData(this._search.allFilteredRecords, false); - } else { - // Just apply DOM filter - this._applyDOMFilter(this._search.filteredIds); - } - }, - /** * Handle search input event (immediate tracking) */ @@ -263,213 +250,292 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) { return; } - // Update the view with filtered results - this._updateViewWithFilteredData(records, true); + // Update the view with filtered results - CRITICAL FIX + this._updateViewWithFilteredData(records); }, /** - * Update view with filtered data - THE KEY METHOD + * Update view with filtered data - COMPLETELY REWRITTEN */ - _updateViewWithFilteredData: function(records, updateState) { + _updateViewWithFilteredData: function(records) { var self = this; - var limit = this.state.limit || 80; - var pageRecords = records.slice(0, limit); - // Method 1: Try DOM filtering first (fastest, preserves input) - var domFilterSuccess = this._tryDOMFiltering(this._search.filteredIds, limit); + // Method 1: Try to filter existing DOM rows first + var domFilterWorked = this._filterExistingRows(); - if (domFilterSuccess) { - // DOM filtering worked, just update pager + if (domFilterWorked) { + // Update pager with correct count this._updatePager(records.length); return; } - // Method 2: Need to update data and re-render - // This happens when DOM doesn't have the records we need - if (updateState && this.state && this.state.data) { - // Update state with filtered data - this.state.data.records = pageRecords; - this.state.count = records.length; - this.state.res_ids = this._search.filteredIds; - - // Clear and re-render - this._clearTableBody(); - this._renderFilteredRows(); - } + // Method 2: Update the actual data and re-render + this._updateStateAndRerender(records); }, /** - * Try DOM filtering first (fastest method) + * Filter existing rows in DOM - ENHANCED METHOD */ - _tryDOMFiltering: function(filteredIds, limit) { - var $rows = this.$('.o_data_row'); - if ($rows.length === 0) { - return false; // No rows to filter + _filterExistingRows: function() { + if (!this._search.filteredIds || this._search.filteredIds.length === 0) { + return false; } var self = this; + var $allRows = this.$('.o_data_row'); + var limit = this.state.limit || 80; var visibleCount = 0; - var foundMatch = false; + var foundAnyMatch = false; - $rows.each(function() { + console.log('Filtering rows. Total rows:', $allRows.length, 'Filtered IDs:', this._search.filteredIds); + + // First pass: hide all rows + $allRows.hide(); + + // Second pass: show matching rows up to limit + $allRows.each(function(index) { var $row = $(this); var rowId = self._getRowId($row); - if (rowId && filteredIds.includes(rowId)) { + console.log('Row', index, 'ID:', rowId, 'Should show:', self._search.filteredIds.includes(rowId)); + + if (rowId && self._search.filteredIds.includes(rowId)) { if (visibleCount < limit) { $row.show(); visibleCount++; - foundMatch = true; - } else { - $row.hide(); + foundAnyMatch = true; + console.log('Showing row', index, 'with ID', rowId); } - } else { - $row.hide(); } }); - return foundMatch; - }, - - /** - * Clear table body - */ - _clearTableBody: function() { - this.$('tbody .o_data_row').remove(); - this.$('.oe_no_results').remove(); - }, - - /** - * Render filtered rows - */ - _renderFilteredRows: function() { - var self = this; + console.log('DOM filtering result - Found matches:', foundAnyMatch, 'Visible count:', visibleCount); - try { - // Try Odoo's internal render methods - if (typeof this._renderRows === 'function') { - var $rows = this._renderRows(); - if ($rows && $rows.length) { - this.$('tbody').append($rows); - this._updatePager(this._search.filteredIds.length); - return; - } - } - - if (typeof this._renderBody === 'function') { - var result = this._renderBody(); - if (result && typeof result.then === 'function') { - result.then(function() { - self._updatePager(self._search.filteredIds.length); - }); - } else { - this._updatePager(this._search.filteredIds.length); - } - return; - } - } catch (err) { - console.warn('Render failed, using fallback:', err); + // If no matches found in DOM, we need to re-render + return foundAnyMatch; + }, + + /** + * Update state and re-render - ENHANCED METHOD + */ + _updateStateAndRerender: function(records) { + var self = this; + var limit = this.state.limit || 80; + var pageRecords = records.slice(0, limit); + + console.log('Re-rendering with filtered data. Total records:', records.length, 'Page records:', pageRecords.length); + + // Update state + if (this.state && this.state.data) { + this.state.data.records = pageRecords; + this.state.count = records.length; + this.state.res_ids = this._search.filteredIds; } - // Fallback: Create rows manually - this._createRowsManually(); + // Clear existing rows + this.$('tbody .o_data_row').remove(); + this.$('.oe_no_results').remove(); + + // Try different rendering approaches + this._tryMultipleRenderMethods(pageRecords); + + // Update pager + this._updatePager(records.length); }, /** - * Create rows manually as last resort + * Try multiple rendering methods - NEW ENHANCED METHOD */ - _createRowsManually: function() { + _tryMultipleRenderMethods: function(records) { var self = this; - var records = this.state.data.records; + var renderSuccess = false; - if (!records || records.length === 0) return; + // Method 1: Try Odoo's _renderRows if available + if (!renderSuccess && typeof this._renderRows === 'function') { + try { + var $rows = this._renderRows(); + if ($rows && $rows.length > 0) { + this.$('tbody').append($rows); + renderSuccess = true; + console.log('Render method 1 succeeded'); + } + } catch (err) { + console.warn('Render method 1 failed:', err); + } + } - records.forEach(function(record) { + // Method 2: Try _renderBody if available + if (!renderSuccess && typeof this._renderBody === 'function') { + try { + var result = this._renderBody(); + if (result) { + if (typeof result.then === 'function') { + result.then(function() { + console.log('Render method 2 succeeded (async)'); + }); + } else { + console.log('Render method 2 succeeded (sync)'); + } + renderSuccess = true; + } + } catch (err) { + console.warn('Render method 2 failed:', err); + } + } + + // Method 3: Manual row creation (fallback) + if (!renderSuccess) { + console.log('Using manual row creation fallback'); + this._createRowsManually(records); + renderSuccess = true; + } + + return renderSuccess; + }, + + /** + * Create rows manually - ENHANCED FALLBACK + */ + _createRowsManually: function(records) { + var self = this; + + if (!records || records.length === 0) { + console.log('No records to create rows for'); + return; + } + + console.log('Creating', records.length, 'rows manually'); + + records.forEach(function(record, index) { var $row = $('