Column position and moving

TreeGrid documentation

There are three column sections in grid - Left (0), Mid (1) and Right (2). In API methods are the sections identified by their indexes (0,1,2).
The Left (0) and Right (2) sections are fixed sections by default and always show all its content and no horizontal scrollbars. It is possible to have scrollable also the Left and Right section, see Section widths.
The Mid (1) section is positioned between Left and Right section and its content can be scrolled horizontally.

Column are placed into its section in input XML, in <LeftCols> (Left), <Cols> (Mid), <RightCols> (Right).
Column position inside section is set by the position of <C> tag inside its XML section <LeftCols>, <Cols>, <RightCols>.
The column position is saved to cookies, so the mentioned position is used only first time. To not save the position to cookies set <Cfg ColsPosLap='1'/> or <ColsLap='1'/>.

The columns can be moved by a user by mouse dragging, inside or among sections, controlled by <C CanMove/> attribute.
Or can be moved by API method MoveCol.
<Cfg> bool

ColMoving

[1]
If columns can be moved by a user - dragged by mouse. Use column CanMove attribute to specify if and how can be individual columns moved.
chg 6.3 <C> int

CanMove

[2/1/0]
If and how column can be moved by a user - dragged by mouse.
0 - no
1 - only inside its section (Left, Mid, Right)
2 - inside and also between sections - user can freeze variable columns and vice versa.
For spanned columns see also Group attribute.
By default it is 0 for Panel, Index, Gantt and ConstWidth columns, 1 for columns added by AutoCols, and 2 for all other columns.
When column has CanMove='0', since 6.3 can be moved columns right to this column in left section, left to it in right section and both side in variable columns.
renamed 9.2 <C> int

Block

[0]
Controls moving column, it is useful especially if there are some cells spanned to or from other columns.
If set to > 0, it is the block the column belongs to. Create blocks that contain the spanned cells. The blocks must be continuous.
The columns can be moved only inside its block and any other column cannot be moved into the block from outside.
The first (left) column in the block cannot be moved within the block and also must stay the first.
The whole block can be moved by dragging the first left column to another location.
It also preserves splitting block of columns to more pages when printing and for column paging.
Since 9.2 it was renamed from Group.
<Cfg> bool

ColsPosLap

Suppresses loading column positions from cookies and always use their positions in input XML.
<Cfg> bool

ColsLap

Suppresses loading column positions, visibility and widths from cookies and always use the settings in input XML.
<Cfg> bool

ShowDrag

[1] Saved to cookies, to not load it, set ShowDragLap='1'
If shows dragged object under mouse cursor. The dragged row(s) or moved column(s).
It can be changed by a user in configuration menu.
new 7.0 <Cfg> int

ScrollColOnDrag

[100]
The step (speed) when automatically scrolling column section horizontally while dragging column on the left or right edge.
new 7.0 <Cfg> bool

AllCols

[0]
If set in input data XML, it says that the XML contains all columns definition and their position in <Cols> tag will change their position in grid.
Useful to set to change already defined columns position in later XML.
It is cleared before every input XML and must be defined before all <LeftCols>,<Cols> and <RightCols> definition.
new 12.0 <C> string

Next

If set in input data XML, it moves or places the column before the Next column. The Next column must already exist.
If it is set to empty string, moves existing column to the end of the section where it is defined.
It is cleared after the column is placed or moved.
<Actions>

ColMove

Attached to OnDragHeader, can be attached only to OnDrag... event
Starts moving column by mouse dragging.
The column can be moved inside Header or to DropCols cells.
It is affects by ColMoving and CanMove attributes.
new 12.0 <Actions>

ColMoveSelected

Attached to OnDragHeader, can be attached only to OnDrag... event
Starts moving selected columns by mouse dragging. Fails if actual column is not selected.
The columns can be moved only inside Header. Ignores Block attributes.
It is affects by ColMoving and CanMove attributes.
upd 12.0 API event void

OnColMove

(TGrid grid, string col, string copy)
Called after column is moved to another position by a user (not by API).
(new 12.0) copy is new column name when the column is copied, not moved.
upd 6.0 API method void

MoveCol

(string col, string tocol, bool right, bool noshow = 0) or (string col, int sec, bool last, bool noshow = 0)
Moves column to new position. If noshow is set, does not display changes and needs to call Render.
a) Moves column col in front of column tocol (or after tocol if right is 1).
b) Moves column col to section sec (0 - left, 1 - mid, 2 - right), to beginning (or to the end if last is 1). Use when destination section is empty.
Remember, moving column is slow process, much slower than moving row, all the column cells must be moved one by one.
Remember, this function can re-render the whole grid in some cases (when it leads to hide or show the whole column section).
chg 7.0 API method void

ChangeColsPositions

(string[ ] leftcols, string[ ] cols, string[ ] rightcols)
Changes positions of all columns in grid and splits them to sections.
All three arguments are Arrays of column names sorted according to their positions in given section.
Since 7.0 it can be called only in OnLoaded or OnCfgLoaded to change the column positions on grid start.
All column names in grid must be given!
It does not save changes to cookies.
It does not update horizontally spanned cells!
new 7.0 API TCol var. int

MainSec

read only
Column section - 0 Left, 1 Mid, 2 Right
chg 7.0 API TCol var. int

Sec

read only
Column section/page - 0 Left, 1 Mid, 2 Right
(New 7.0) When set ColPaging, it is number of column page, 0 Left, 1 - (N-2) Mid, (N-1) Right, where N is the ColNames.length
API TCol var. int

Pos

read only
Column position inside its section / page Sec, from 0. All columns including hidden.