Skip to Content
Menu
This question has been flagged
3 Replies
1857 Views

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.

Avatar
Discard
Best Answer

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

Avatar
Discard

Thank You for your support

Best Answer

Thank You for your support Pushpendra

Avatar
Discard
Author Best Answer

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




Avatar
Discard


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

Related Posts Replies Views Activity
2
Apr 23
3646
1
Mar 22
1548
1
Oct 22
7640
0
Jul 22
2432
1
Jun 22
5665