To allow the user moves a column, you must set a flag at the grid scope by providing an input DikeGrid property named allowColumnDragging. Its default value is false.
You can change the value of the allowColumnDragging property at runtime.
You can open the Floating Configuration Panel of the live demo and change the value of the property allowColumnDragging.
Draggable Columns
You can make a column movable by providing a property named draggable. Its default value is false.
Be aware that you can not change the draggable property at runtime. Use the locked property instead if you want the user not to move a column at runtime. For more details, see the Column Pinning section.
All columns and column groups are movable except the Name column in the root group and the Name and Surname columns under the Complete Name group.
We have enabled the row grouping to move columns to the group panel. Columns Surname and Hire Date from the root group are groupable. Gender and Age columns under the Personal Info group are groupable as well.
All columns are in the center panel except the Hire Date column in the right panel.
You can move only data columns to the group panel, not column groups.
When you move a column group to the group panel using the API, the movement inserts only the descendant data columns into the group panel.
Column movements
Once we have established some columns as draggable, be aware of the valid movements a column could take.
For the description of the following movements, it will be helpful to grasp the Gutters structure of the DikeGrid.
Interchange Columns
This movement will swap two columns. The source column will take the destination column's place and vice versa. For this movement, the following rules apply:
The columns must belong to the same group of columns.
You can interchange columns that belong to the Content panels.
If you try to swap a broken group, you will join the group in the destination panel.
Move Column Before
You can move a column before another column.
Let us say that you can move a given column at the left side of the target column. The actual movement will insert the given column at the left-gutter of the target column. Therefore, consider the following rules:
Columns must belong to the same group of columns.
The target column must belong to the right panel because columns have their gutter at their left.
If the target column lives in the left, center panel, or group panel, it must be the first column because they have both gutters.
Move Column After
You can move one column after another column.
Same as before, let us say that you can move a given column at the right side of the target column. The actual movement will insert the given column at the right-gutter of the target column.
The rules are:
Columns must belong to the same group of columns.
The target column must belong to the group, left or center panel because columns have their gutter at their right.
If the target column lives in the right panel, it must be the last column because it has both gutters.
Column to panel
This movement is possible when you drag a column to the left or right grid border or use the Pinning submenu of the Column Context Menu.
Drag a column to the grid's borders
Drag a column to the left or right grid border, as you can see in the following gif.
Using the Column Context Menu
Now, click on any Column Context Menu and select a panel to move the column.
It is possible to move all panel columns to another panel using the columnAPI.
Breaking a column group
You can take a column that belongs to a column group and place it in another panel. This move grabs the column with its parent column and its parent, and so forth until the root.
The movement's outcome is a broken group. For example, we moved the Gender column to the left panel. See the final state of the Personal Info group in the following screenshot.
Unbroken column groups
If you do not want the user breaks a group, make its child columns non-draggable, as we did for Name and Surname columns under the Complete Name column group.
We added the form selector above the dike-grid selector, generating the following output:
With the previous UI, you can do the following tasks:
You can choose the source column or the source panel from the first select control.
Depending on your selected option, the second dropdown control will have a proper destination place. For instance, if you choose a column, the destination control will contain all columns of the same group and panels the column does not live.
The radio-button group has methods that involve column between column movements.
When you select panels, the corresponding button is enabled.
It is essential to notice that we are listening to any change in the DikeGrid's columns, attaching a subscription to the columnsChangeObservable from the DikeGridColumnDef.
Every time we receive a new set of columns, we flat them into a single array, invoking the method flatColumns(). So indeed, we are flattening the column groups, traversing them recursively.
If you see the content of the source dropdown control, you see the columns Hire Date, Employee Id, Personal Info group, Complete Name group, then Name and Surname columns, Gender and Age columns, etc.
The non-draggable columns are disabled, such as Name and Surname, under the Complete Name group.
Column Moving Events
Every previous movement emits an event of type DikeColumnMoveEvent. We listen to the columnMove event at the grid scope.
As you can see, some fields are not required. However, depending on the type of movement, those fields are provided.
Movement
DikeColumnMoved
Interchange Columns
type: swap-columns.
movedColumns: The source and destination columns.
Interchange Columns
type: join-column-groups.
movedColumns: The joined column group.
destinationPanel: The panel the broken-destination group lives.
Move Column Before
type: column-before.
movedColumns: The source column.
beforeColumn: The target column.
destinationPanel: The panel the target column lives.
Move Column After
type: column-after.
movedColumns: The source column.
afterColumn: The target column.
destinationPanel: The panel the target column lives.
Column to panel
type: columns-to-panel.
movedColumns: The source columns or all panel columns.
destinationPanel. The provided panel is the destination panel.
You can open the dev console for the live demo and see the emitted event.
Summary
Before defining which columns will be movable, you must allow this action by providing a property named allowColumnDragging at the grid scope. To move a column, you must define a column as draggable. You can interchange columns only from the Content panels, and you can only add data columns to the group panel. You can move columns using the Column Context Menu as well.