Search Here

Use Handle Widget in Odoo to Reorder Records in Tree View

 In this article, you will learn how to use the Odoo15 Handle Widget feature to reorder records in the tree or list view. By using this widget (widget="handle") you can drag and drop records in the tree view and change their order.

Use Handle Widget in Odoo to Reorder Records in Tree View

Drag and Reorder Records in Tree View using Handle Widget in Odoo

To reorder records located in the tree view, we are going to use the widget="handle" feature provided by Odoo15. By using this we can move tree view records up and down by dragging them and setting their order dynamically.

Read More: How to Use ProgressBar, Gauge and Percentpie Widgets In Odoo

Below is the code snippet of reordering records in a tree view using widget="handle".

To achieve this feature you just need to add an Integer field in your model just like below.

class your_model(models.Model):

    _name = 'your.model'

    sequence = fields.Integer(default=10,help="Gives the sequence order when displaying a list of records.")

Read More: Color Field and Color Picker (color_picker) Widgets in Odoo

After that use widget="handle" in tree view like below.


<field name="sequence" widget="handle"/>


Now upgrade the module and see your changes, you just see a small up and down arrow before all of your fields, just drag the record to reorder them and drop it into your desired location. 

Read More: Enable Tracking (track_visibility) for Fields in Odoo

Here I will discuss one important thing is that when you refresh the page after reordering the records, your changes will be flushed. 

If you want that your reordering will exist after refreshing the page then use the below code in your model.

Read More: Show and Display Sticky Notification in Odoo

class your_model(models.Model):

    _name = 'your.model'

    _order = 'sequence,id'

    sequence = fields.Integer(default=10,help="Gives the sequence order when displaying a list of records.") 

Post a Comment

0 Comments