콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
2587 화면

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.

아바타
취소
베스트 답변

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 😀.

아바타
취소

Thank You for your support

베스트 답변

Thank You for your support Pushpendra

아바타
취소
작성자 베스트 답변

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">




아바타
취소


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;
});
-----------------------------------------------------------------------------------------------------------

관련 게시물 답글 화면 활동
2
4월 23
4206
1
3월 22
2019
1
10월 22
8557
0
7월 22
2887
1
6월 22
6281