This question has been flagged
3 Replies
24738 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"?>
<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

Avatar
Discard

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

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

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.

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?

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.

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?

Avatar
Discard
Author

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

Author

I'm in Odoo v8

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

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

Author

Thanks Ivan

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