Help

5

How to sort according a custom column in a view?

Avatar
Pascal Tremblay

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"?>
<openerp>
    <data>

        <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"/>
                </tree>
            </field>
        </record>


    </data>
</openerp>

 

Thanks

5 Comments
Avatar
Discard
Avatar
Jeff Beidler
-

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

Avatar
Ivan
-

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

Avatar
Jeff Beidler
-

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.

Avatar
Jeff Beidler
-

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?

Avatar
Ivan
-

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.

2 Answers
0
Avatar
Cyril Gaspard (GEM)
Best Answer

Hi,

another way to test, perhaps try to redefine _order attribute of your class:

class Myclass(models.Model):

    _inherit = 'my.class'

    _order = 'id desc, name desc'

else you can tried to use attribute  default_order in tree or kanban view

Regards

Avatar
Discard
0
Avatar
Ivan
Best Answer

@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?

5 Comments
Avatar
Discard
Avatar
Pascal Tremblay
-

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

Avatar
Pascal Tremblay
-

I'm in Odoo v8

Avatar
Ivan
-

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

Avatar
Ivan
-

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

Avatar
Pascal Tremblay
-

Thanks Ivan