
Learn how to implement the widget handle in Odoo to reorder records using drag-and-drop functionality, enhancing usability and data management.
In Odoo, the widget handle is an essential feature that enables users to reorder items in a list view using drag-and-drop functionality. This is especially useful for setting custom sequences for records, such as priority lists or customized sorting orders in a form or tree view.
The widget handle is a UI feature that allows users to manually adjust the order of records in a list. This widget is displayed as a "handle" icon, which users can drag to change the position of list items. It works in combination with Odoo’s sequencing fields to control the order of records.
To implement the widget handle, we need a few simple steps:
First, add a field to your model that will hold the sequence order. Here’s an example in Python:
<from odoo import models, fields>
class Task(models.Model):
_name = 'project.task'
_order = 'sequence' # Set default ordering by sequence field
sequence = fields.Integer(string="Sequence", default=10)
Explanation:
In the list view, add the handle widget on the sequence field. This allows users to drag and reorder records directly in the view:
<record id="view_task_tree" model="ir.ui.view">
<field name="name">project.task.tree</field>
<field name="model">project.task</field>
<field name="arch" type="xml">
<tree string="Tasks" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="priority"/>
</tree>
</field>
</record>
Explanation:
The widget handle allows for easy, intuitive customization of data order without requiring users to change sequence numbers manually. By dragging records, users can rearrange items quickly, making it an ideal solution for managing priority lists, custom ordering of tasks, or any other sortable list of records.
Here are some common use cases where the widget handle is beneficial:
The widget handle in Odoo provides an efficient way to manage the order of records directly from the list view. With a simple configuration, users can adjust record positions using drag-and-drop functionality, improving both usability and the overall user experience in Odoo.
Your email address will not be published. Required fields are marked *