From ac7303bb7f611a7d4e2d0aa465c77f387eb88dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Sat, 17 May 2025 18:29:38 +0800 Subject: [PATCH] 1 --- .../list_view_sticky_header_and_column.scss | 2 +- tree_view_advanced_filter/__manifest__.py | 6 +- .../js/list_view_sticky_header_and_column.js | 65 +++++++++++++++++++ .../list_view_sticky_header_and_column.scss | 51 +++++++++++++++ .../list_view_sticky_header_and_column.xml | 49 ++++++++++++++ .../static/src/css/gantt_style.css | 9 +++ 6 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/js/list_view_sticky_header_and_column.js create mode 100644 tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/scss/list_view_sticky_header_and_column.scss create mode 100644 tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/xml/list_view_sticky_header_and_column.xml diff --git a/list_view_sticky_header_and_column/static/src/scss/list_view_sticky_header_and_column.scss b/list_view_sticky_header_and_column/static/src/scss/list_view_sticky_header_and_column.scss index d221c0e92..8bc0078b0 100644 --- a/list_view_sticky_header_and_column/static/src/scss/list_view_sticky_header_and_column.scss +++ b/list_view_sticky_header_and_column/static/src/scss/list_view_sticky_header_and_column.scss @@ -1,7 +1,7 @@ .sticky-column { position: sticky !important; background-color: white; - z-index: 2; + z-index: 4 !important; } .o_list_view .o_list_table td.sticky-column { z-index: 4 !important; diff --git a/tree_view_advanced_filter/__manifest__.py b/tree_view_advanced_filter/__manifest__.py index 1c6a229ce..6ecbf76cc 100644 --- a/tree_view_advanced_filter/__manifest__.py +++ b/tree_view_advanced_filter/__manifest__.py @@ -57,7 +57,7 @@ "license": "OPL-1", "price": 95.00, "currency": "USD", - "depends": ["web", "sale_management"], + "depends": ["web", "sale_management", "account", "purchase", "hr_expense"], "data": [], "assets": { "web.assets_backend": [ @@ -65,8 +65,12 @@ "tree_view_advanced_filter/static/src/libs/**/*", "tree_view_advanced_filter/static/src/tree_view_advanced_filter/**/*", "tree_view_advanced_filter/static/src/web_list_num/**/*", + "tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/js/*", + "tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/xml/*", + "tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/scss/*" ] }, + "images": ["static/description/banner.jpg"], "installable": True, "auto_install": False, diff --git a/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/js/list_view_sticky_header_and_column.js b/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/js/list_view_sticky_header_and_column.js new file mode 100644 index 000000000..0930bfa4b --- /dev/null +++ b/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/js/list_view_sticky_header_and_column.js @@ -0,0 +1,65 @@ +/** @odoo-module **/ +/** This file will used to stick the selected header and column in the list view **/ +import { patch } from "@web/core/utils/patch"; +import { ListRenderer } from "@web/views/list/list_renderer"; +patch(ListRenderer.prototype, { + /** super the setup function **/ + setup() { + super.setup(); + + }, + /** + * function defining the button having t-on-click _onClick + */ + _onClickIcon(ev, record) { + ev.preventDefault(); + ev.stopPropagation() + const $clickedHeader = $(ev.currentTarget).closest('th'); + const columnIndex = $clickedHeader.index(); + console.log(this.__owl__.bdom.parentEl) + $(this.__owl__.bdom.parentEl.querySelectorAll('.sticky-column')).removeClass('sticky-column'); + console.log($(this.__owl__.bdom.parentEl.querySelectorAll('.sticky-column')).removeClass('sticky-column')) + $(this.__owl__.bdom.parentEl.querySelectorAll('.clicked-header')).removeClass('clicked-header'); + $clickedHeader.addClass('clicked-header'); + const $tableHeaders = $(this.__owl__.bdom.parentEl.querySelectorAll('.o_list_table th')); + const $tableRows = $(this.__owl__.bdom.parentEl.querySelectorAll('.o_list_table tr')); + const $tfootRow = $(this.__owl__.bdom.parentEl.querySelectorAll('.o_list_table tfoot tr')[0].children); + const $selectedFooterCells = $tfootRow.filter(`td:nth-child(-n+${columnIndex + 1})`); + $selectedFooterCells.addClass('sticky-column'); + const $selectedSearchTds = $(this.__owl__.bdom.parentEl.querySelectorAll(`.search_td:nth-child(-n+${columnIndex + 1})`)); + $selectedSearchTds.removeClass('sticky-column').css('left', ''); + $selectedSearchTds.addClass('sticky-column'); + const $selectedColumns = $(this.__owl__.bdom.parentEl.querySelectorAll(`.o_data_row td:nth-child(-n+${columnIndex + 1})`)); + const $selectedHeaderCells = $tableHeaders.filter(`th:nth-child(-n+${columnIndex + 1})`); + $tableHeaders.removeClass('sticky-column').css('left', ''); + $(this.__owl__.bdom.parentEl.querySelectorAll('.o_data_row td')).removeClass('sticky-column').css('left', ''); + $selectedColumns.addClass('sticky-column'); + $selectedHeaderCells.addClass('sticky-column'); + $tableHeaders.filter('.sticky-column').css('top', '0'); + const $targetColumn = $selectedColumns.eq(columnIndex); + // const targetLeftPosition = $targetColumn.position().left; + const columnsToAdjust = columnIndex + 1; + $tableRows.each(function (index, row) { + const $headerCells = $(row).find('th'); + const $rowCells = $(row).find('td'); + for (let i = 0; i < columnsToAdjust; i++) { + if ($headerCells.eq(i).length > 0) { + $headerCells.eq(i).css('left', `${$headerCells.eq(i).position().left}px`); + } + if ($rowCells.eq(i).length > 0) { + $rowCells.eq(i).css('left', `${$rowCells.eq(i).position().left}px`); + } + } + }); + }, + /** + * super onClickSortColumn function and remove the icon and element having the class sticky-column + */ + onClickSortColumn(column) { + super.onClickSortColumn(...arguments); + $(this.__owl__.bdom.parentEl.querySelectorAll('.sticky-column')).removeClass('sticky-column'); + $(this.__owl__.bdom.parentEl.querySelectorAll('.clicked-header')).removeClass('clicked-header'); + const $tableHeaders = $(this.__owl__.bdom.parentEl.querySelectorAll('.o_list_table th')); + $tableHeaders.removeClass('sticky-column').css('left', ''); + } +}); diff --git a/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/scss/list_view_sticky_header_and_column.scss b/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/scss/list_view_sticky_header_and_column.scss new file mode 100644 index 000000000..8bc0078b0 --- /dev/null +++ b/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/scss/list_view_sticky_header_and_column.scss @@ -0,0 +1,51 @@ +.sticky-column { + position: sticky !important; + background-color: white; + z-index: 4 !important; +} +.o_list_view .o_list_table td.sticky-column { + z-index: 4 !important; + background-color: white; +} +.o_list_view .o_list_table thead { + position: sticky; + top: 0; + z-index: 3; + background-color: white; +} +.o_list_view .o_list_table th.sticky-column { + z-index: 4; + background-color: white; +} +.o_account_reports_page .table-responsive { + overflow-x: auto; + overflow-y: visible; +} +.table-responsive { + overflow: visible; +} +.o_list_view .table-responsive .table thead { + z-index: 5; +} +.o_list_renderer .o_list_table thead { + position: sticky; + top: 0; + z-index: 6; +} +th.sticky-column::before { + content: ""; + position: absolute; + width: 5px; + height: 100%; + background: white; + top: 0; + left: -4px; +} +.fa-thumb-tack { + display: none; +} + +th:hover .fa-thumb-tack, +th.clicked-header .fa-thumb-tack { + display: block; +} diff --git a/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/xml/list_view_sticky_header_and_column.xml b/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/xml/list_view_sticky_header_and_column.xml new file mode 100644 index 000000000..82d9ff4d7 --- /dev/null +++ b/tree_view_advanced_filter/static/src/list_view_sticky_header_and_column/xml/list_view_sticky_header_and_column.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/yuthon_hr_attendance/static/src/css/gantt_style.css b/yuthon_hr_attendance/static/src/css/gantt_style.css index 812fbf9b1..bd88685cf 100644 --- a/yuthon_hr_attendance/static/src/css/gantt_style.css +++ b/yuthon_hr_attendance/static/src/css/gantt_style.css @@ -10,3 +10,12 @@ text-overflow: clip !important; // 移除省略号(或直接不设置) min-width: max-content !important; // 按内容撑开列宽(可选) } + +.o_list_renderer .o_list_table{ + table-layout: auto !important; +} + +.o_list_renderer .o_list_table > thead > tr > th{ + max-width: max-content !important; +} +