I want the attribute table in QGIS to be automatically sorted by the column I want, so that I don't have to click on the right column every time.
At the moment, when I open the attribute table, the sorting is done on the "ID"
column, and the numbers are in random order, not in descending or ascending order.
Is this currently possible?
Best Answer
Let's assume there is a point layer called 'points_test' with its attribute table, see image below.
As you can see there are two fields in it:
By default my values in the attribute table are sorted by
"id"
fields. How one can know that?Open Attribute Table (F6) and proceed with
Right Mouse Click on the column header > Sort...
Now, I will configure attribute table sort order and switch to another field. In the pop-up window insert the desired field, in my case it is
"TEST"
, instead of"id"
.And now as you can see that my attribute table was visually changed into different sorting order evoked from the
"TEST"
field.The same action can be performed with PyQGIS.
Proceed with
Plugins > Python Console > Show Editor
and paste the script belowPress
Run script
and get the output the same as was achieved above.References: