17

In a QGIS 2.18.20 attribute table I have some values with random numbers, but at the print composer I want to show them with order (clockwise). So I made a new integer column, and added numbers with the way of sorting I want to appear at the print composer.

Now I can't find a way to hide the column I used for sorting the numbers. I need to use it to sort the columns, but when I delete it or do something similar the order disappears. Is there a way to keep the sorting the way I want, but to hide the sorting column? Can I do it with a different way? In the picture, "field 1" is the point number, field2&3 are the coordinates and ORDER is the sorting column

field 1 has the random numbers ORDER is the sorting column

Taras
  • 32,823
  • 4
  • 66
  • 137
Pitheas
  • 741
  • 3
  • 15

3 Answers3

14

I suggest to use a Virtual layer through Layer > Add Layer > Add/Edit Virtual Layer.

If the SQL in virtual layers would give the same result than SQL that is fired directly against databases then the following should work

select a.field_1, a.field_2, a.field_3
from (
    select field_1, field_2, field_3, "ORDER"
    order by "ORDER"
    ) as a;

The result seems to work correctly in the print composer with QGIS 3.8.3. I wasted some time by trying to check the result by opening the attribute table of the new virtual layer in the map window with Open Attribute Table but it does not show the records like they are sorted with ORDER BY. Records are perhaps sorted also spatially. Fortunately in the print composer the order was logical and right.

My query from Create a Virtual Layer

enter image description here

Original table and sorted virtual table in Print Composer

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
user30184
  • 65,331
  • 4
  • 65
  • 118
8

You could do this in a different way by sorting the layer before using the composer. So:

  1. Sort your layer with MMQGIS (plugin) by "ORDER" --> ascending.
  2. Show this new table in composer and remove the field.

Here so screen shots: Here is the data: enter image description here

Sort: enter image description here enter image description here

Check the differences: enter image description here

Plot the sorted table without that field: enter image description here

Fran Raga
  • 7,838
  • 3
  • 26
  • 47
César Arquero Cabral
  • 3,439
  • 1
  • 16
  • 53
1

I don't have 2.18 installed anymore, but I remember doing this for a project last year:

  • in the map composer, go to the table's item properties
  • in the main properties tab, click on Attributes

From there you can manipulate your columns (change field order or even hide a field from output) and choose how to sort field values (ascending or descending).

edit: Both actions (sorting from field and hiding field) can't be used concurrently. If field is hidden, it cannot be chosen as a sorting rule.

Gabriel
  • 3,136
  • 13
  • 33
  • That is the problem, when I short them,following the ORDER column, that column is no needed anymore for displaying in the composer. – Pitheas Aug 22 '18 at 16:08
  • After checking it out, I see what you mean. This could be a feature request for a future version, the ability to use a field from the table item for sorting while being able to hide it in composer. – Gabriel Aug 22 '18 at 17:03