i re arrange the columns of table manually from the sidebar and opened the console, i got the api,
_grist_Views_section_field, but im not sure what field i should change to re-order my columns.
So if i have A-B-C, and i want it to be C-A-B. what should i do?
And how can i get the col id, because in the api get - docs/docId/tables/tableId/columns the id is the name of the col not the number.
Hi @Ghady_Gergie , and welcome to the community!
You are right that _grist_Views_section_field
is the right place to change. This determines which fields are shown in the “view section” (a widget on a page). The section is determined by parentId
and the order is determined by parentPos
.
To rearrange, here are suggested steps:
- Find the ID of the view section. Most easily, hover over the “Download as CSV” link for that section, and look for
viewSection=N
parameter. Use that numberN
below. - Find column of interest using
GET /columns
API. Get its numeric ID using.fields.colRef
. - Find the list of fields in viewSection using
GET /records
API for_grist_Views_section_field
table, with filter{"parentId": [N]}
(using view-section number from above) - In this list of fields, one will have
colRef
from step 2, get the ID of that field (let’s call itfieldRef
below). All fields will haveparentPos
— order is determined by sortedparentPos
. If you setparentPos
of a field toparentPos
of an existing field, it will get adjusted to be just before that existing field. If you setparentPos
to null, it will get adjusted to go at the end. - Use
PATCH /records
endpoint for_grist_Views_section_field
with a payload like{"records": [{"id": fieldRef, "fields": {"parentPos": newPosition}}]}
Hope this helps!