Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to sort according a custom column in a view?

Pascal Tremblay
on 1/20/15, 6:26 AM 3,421 views

Hello there,

Here is my code to customize « external identifiers » view. I added a ID column.

But when I add a new column like this in a view, I CAN NOT sort lines according to this new column. If I click the header of the table, nothing arrives. How could it work?

Also, how could I get the little triangle icon in the header when the column is sorted? (see the triangle at the right of Model Name)



<?xml version="1.0" encoding="utf-8"?>

        <record id="base.view_model_data_list" model="ir.ui.view">
            <field name="model">ir.model.data</field>
            <field name="arch" type="xml">
                <tree string="External Identifiers">
                    <field name="id"/>
                    <field name="complete_name"/>
                    <field name="display_name"/>
                    <field name="model" groups="base.group_no_one"/>
                    <field name="module" invisible="1"/>
                    <field name="res_id"/>




I would like to know how to make an added column sortable, too!

Jeff Beidler
on 1/22/15, 7:04 PM

@Jeff, in general all stored columns are sortable. I've just learned that in v8 the ID column is not. So, as long as your column is stored in the database you can just add the field into the tree view and it will be sortable.

on 1/22/15, 10:50 PM

I added the "Internal Reference" (default_code) field to the Product list view. Unfortunately, it remains unsortable. I can click on the header cell all I want, but it doesn't work. There must be some way that you have to designate the column as sortable.

Jeff Beidler
on 1/23/15, 11:38 AM

Ah! I looked in the database, and I see that "default_code" is actually stored in product.product, not product.template, which is the base table for the Products list view. Is that why it's not sortable? It's not a member of the base table?

Jeff Beidler
on 1/23/15, 11:59 AM

I guess so. However I'm amazed if you can display default_code in a view based on product.template. New things to learn everyday. Thanks for sharing.

on 1/24/15, 1:51 AM


| 5 3 6
Jakarta, Indonesia
On 1/20/15, 7:15 AM

@Pascal, I tried adding the id field as you have done (using OpenERP v7) and I can sort based on the ID field.  Note that you can only sort by 1 column at any time.  Note that you cannot sort by Complete ID and Display Name as they are function fields.  You did not redefined the ID field, did you?

I didn't redefined the ID field. Should I? How?

Pascal Tremblay
on 1/20/15, 7:27 AM

I'm in Odoo v8

Pascal Tremblay
on 1/20/15, 7:28 AM

No, you shouldn't need to redefine the field. Haven't tried it in v8.

on 1/20/15, 8:07 AM

@Pascal I've tried on v8. It seems that all ID columns are deemed unsortable in v8. If you add other fields like create_uid, you can still sort by that column. Sorry, can't help you further on this.

on 1/20/15, 11:54 PM

Thanks Ivan

Pascal Tremblay
on 1/23/15, 6:49 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 1/20/15, 6:26 AM
Seen: 3421 times
Last updated: 3/23/16, 11:19 AM