ASPxClientGridView.SetColumnLayout(columnLayout) Method
Applies the specified column layout to the grid.
Declaration
SetColumnLayout(
columnLayout: any
): void
Parameters
Name | Type | Description |
---|---|---|
columnLayout | any | An object that contains the column layout. |
Remarks
Use the GetColumnLayout and SetColumnLayout
methods to save and restore the grid column layout.
Limitations
- The
SetColumnLayout
method operates with column states stored on the client. If the layout has been changed on a callback, for instance, if a column has been hidden, it does not exist on the client side anymore. The grid cannot show or hide columns completely on the client side without sending a request to the server and theSetColumnLayout
method has no effect. - When the ProcessColumnMoveOnClient property is set to
false
, theSetColumnLayout
method has no effect.
Example
The following example illustrates how to get and restore a column’s state on the client side.
The ASPxClientGridView.GetColumnLayout is used to get a column’s state.
var initialColumnLayout = null;
function Grid_Init(s, e) {
initialColumnLayout = s.GetColumnLayout();
}
It returns an object that provides the following fields:
column
field - Provides all the column’s information.visibleIndex
field - Provides the column’s visible index.parentColumn
field - Provides the parent column’s information. This field is null if you don’t use the banded columns.
{ “column”: ASPxClientGridViewColumn, “visibleIndex”: -1, “parentColumn”: ASPxClientGridViewColumn },
To restore the layout, use the client-side ASPxClientGridView.SetColumnLayout
method and pass the previously obtained or customized layout.
function RestoreColumnLayout() {
grid.SetColumnLayout(initialColumnLayout);
}
Result code:
function click() {
RestoreColumnLayout();
}
var initialColumnLayout = null;
function Grid_Init(s, e) {
initialColumnLayout = s.GetColumnLayout();
}
function RestoreColumnLayout() {
grid.SetColumnLayout(initialColumnLayout);
}
<dx:ASPxGridView ID="ASPxGridView1" runat="server" ClientInstanceName="grid"
AutoGenerateColumns="False" DataSourceID="AccessDataSource1" KeyFieldName="ProductID">
<Columns>
<dx:GridViewCommandColumn ShowEditButton="True" VisibleIndex="7" />
<dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="2" />
<dx:GridViewDataTextColumn FieldName="SupplierID" VisibleIndex="3" />
<%-- ... --%>
</Columns>
<SettingsBehavior ProcessColumnMoveOnClient="true" ColumnMoveMode="ThroughHierarchy" />
<ClientSideEvents Init="Grid_Init" />
</dx:ASPxGridView>
See Also