Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

Prevent tree view from sorting when clicking on headers (solved)

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
sorttree_viewv15Javascript
3 Trả lời
3555 Lượt xem
Ảnh đại diện
Maximiliano Gamón

Update: Pushpendra solved it! Thanks an immense lot!! I would mark it as fixed or upvote but I can't because of karma. Thanks again! 

Hi! I'm new in the forums, this is my first post. I have been working as an Odoo technical developer for the last six months and it's a huge pleasure to be part of this awesome community. My name is Max, I'm from Argentina.

Right now I am trying to get a tree view (in Odoo 15) to stop sorting when its headers are clicked. So far I have tried this:



odoo.define('production_operator_missiongroup.custom_list_renderer', function (require) { "use strict";

console.log("Javascript works!")

var ListRenderer = require('web.ListRenderer');
var CustomListRenderer = ListRenderer.extend({
​ ​events: _.extend({}, ListRenderer.prototype.events, {
'click thead th.o_column_sortable': '_onSortColumn',
}),

_onSortColumn: function (ev) {
var viewId = 'production_operator_missiongroup.view_production_work_tree_operator';

if (this.state && this.state.id === viewId) {
ev.preventDefault();
​ ​ ​return false;
​}
return this._super.apply(this, arguments);
},
});
return CustomListRenderer;});

But that view is still getting sorted /sigh/. This .js file was successfully imported and that log is being logged. I would be veery grateful for some help with this, the Javascript framework is still a huge weak spot in my Odoo knowledge and can barely grasp it.

0
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Pushpendra
Câu trả lời hay nhất

Hi Maximiliano Gamón,


Problem with your code is to check the viewID with the state id, List view renderer doesn't have viewID that you are expecting.


You can try these steps

1. Add a custom class in your tree view i.e. disable_sort

tree class="o_sale_order disable_sort" >

2. Override _onSortColumn function in list_renderer.js file like this


odoo.define('production_operator_missiongroup.custom_list_renderer', function (require) {

"use strict";

console.log("Javascript works!");

var ListRenderer = require('web.ListRenderer');
var CustomListRenderer = ListRenderer.include({

events: _.extend({}, ListRenderer.prototype.events, {
'click thead th.o_column_sortable': '_onSortColumn',
}),

_onSortColumn: function (ev) {
if (this.$el.hasClass('disable_sort')) {
ev.preventDefault();
return false;
}
return this._super.apply(this, arguments);
},
});

return CustomListRenderer;
});


I hope this solves your problem 😀.

3
Ảnh đại diện
Huỷ bỏ
Suryansh Pratap Singh

Thank You for your support

Ảnh đại diện
Varun Singh
Câu trả lời hay nhất

Thank You for your support Pushpendra

0
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Maximiliano Gamón
Tác giả Câu trả lời hay nhất

Thanks a huge lot Pushpendra for your answer! 
I'm sorry to say it did not work, but I learned a lot from it.

I added the class, changed the _onSortColumn as you said, but nothing happened.

I added a console.log before the if just to see if it ever ran, and it is never logged. But the log at the start of the .js file is properly being logged, so it is being imported. 

Is it possible that _onSortColumn isn't what I should target? I've been checking out list_renderer.js and it would seem that it is. But I can barely understand. Luckily, I have permission to read the Javascript Framework at the Odoo docs, three full hours just to study. If you know of any other good source of knowledge on the topic, I would be really grateful too.

Updated .js file:

odoo.define('production_operator_missiongroup.custom_list_renderer', function (require) {    "use strict";

console.log("Javascript works!")

var ListRenderer = require('web.ListRenderer');
var CustomListRenderer = ListRenderer.extend({
​ ​events: _.extend({}, ListRenderer.prototype.events, {
'click thead th.o_column_sortable': '_onSortColumn',
}),

_onSortColumn: function (ev) {
​ ​ ​if (this.$el.hasClass('disable_sort')) {
ev.preventDefault();
​ ​ ​return false;
​}
return this._super.apply(this, arguments);
},
});
return CustomListRenderer;});

Updated tree view:


production.work.tree
production.work

​ ​class="disable_sort">
​ ​
​


0
Ảnh đại diện
Huỷ bỏ
Pushpendra


Hi Maximiliano Gamón,
There is an issue with your code, you are trying to extend the ListRenderer instead of extending you have to override the ListRenderer.
I have fixed your code JS code, check it and let me know if it is working

-----------------------------------------------------------------------------------------------------------
odoo.define('production_operator_missiongroup.custom_list_renderer', function (require) {

"use strict";

console.log("Javascript works!");

var ListRenderer = require('web.ListRenderer');
var CustomListRenderer = ListRenderer.include({

events: _.extend({}, ListRenderer.prototype.events, {
'click thead th.o_column_sortable': '_onSortColumn',
}),

_onSortColumn: function (ev) {
if (this.$el.hasClass('disable_sort')) {
ev.preventDefault();
return false;
}
return this._super.apply(this, arguments);
},
});

return CustomListRenderer;
});
-----------------------------------------------------------------------------------------------------------

Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Bài viết liên quan Trả lời Lượt xem Hoạt động
How to get action id from javascript? (Odoo 15) Đã xử lý
v15 Javascript
Ảnh đại diện
Ảnh đại diện
2
thg 4 23
5166
how to get user object inside templates odoo 15
v15 Javascript
Ảnh đại diện
Ảnh đại diện
1
thg 3 22
2709
How to create Read Only tree view in odoo 15?
readonly tree_view v15
Ảnh đại diện
Ảnh đại diện
1
thg 10 22
9664
How to use AJAX request to update a field automatically in website form in Odoo15
ajax v15 Javascript
Ảnh đại diện
0
thg 7 22
3709
How to inherit/override function in js odoo15 Đã xử lý
js v15 Javascript
Ảnh đại diện
1
thg 6 22
7255
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now