Tab

GridViewDataColumn.SortIndex Property

Gets or sets the column's position among sorted columns.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

Declaration

[DefaultValue(-1)]
public int SortIndex { get; set; }
<DefaultValue(-1)>
Public Property SortIndex As Integer

Property Value

Type Default Description
Int32

-1

An integer value that specifies the zero-based column's index among sorted columns. -1 if data is not sorted by this column.

Remarks

The ASPxGridView allows data sorting by multiple columns. Once a column is sorted, it is automatically added to the collection of sorted columns. If no columns were previously sorted, the column becomes the only element in the collection and gets the 0 sort index. If sorting by one more columns, the newly sorted column is appended to the collection and gets the 1 index, etc.

When data is sorted by multiple columns, you can change the position (order) of sorted columns using the SortIndex property. Note that changing the sorted columns position changes order of data rows.

Setting the SortIndex property to a non-negative integer, the column is added to the sorted columns list. The column's GridViewDataColumn.SortOrder property is automatically set to ColumnSortOrder.Ascending. Setting a column's SortIndex property value to -1 cancels data sorting by this column.

Sorting is allowed if the ASPxGridBehaviorSettings.AllowSort property is set to true.

Example

The following example illustrates how to use the SortIndex property.

Web Forms approach:

NOTE

For a full example, see the ASPxGridView - Customization Dialog demo.

<dx:ASPxGridView ID="Grid" runat="server" DataSourceID="ProductsDataSource" 
    EnableRowsCache="false" Width="100%">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="ProductName">
            <Settings AutoFilterCondition="Contains" />
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataComboBoxColumn FieldName="CategoryID" Caption="Category Name" SortIndex="0" SortOrder="Ascending" AdaptivePriority="1">
            <PropertiesComboBox DataSourceID="CategoriesDataSource" ValueField="CategoryID" TextField="CategoryName" ValueType="System.Int32" />
            <Settings AllowHeaderFilter="True" AllowAutoFilter="False" SortMode="DisplayText" />
            <SettingsHeaderFilter Mode="CheckedList" />
        </dx:GridViewDataComboBoxColumn>
        ...
    </Columns>
</dx:ASPxGridView>

MVC approach:

NOTE

For a full example, see the GridView - Customization Dialog demo.

@Html.DevExpress().GridView(settings => {
    settings.Name = "GridView";
    settings.SettingsCustomizationDialog.Enabled = true;
    ...
    settings.Columns.Add(c => {
        c.FieldName = "ProductName";
        c.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
    });
    settings.Columns.Add(c => {
        c.FieldName = "CategoryID";
        c.Caption = "Category Name";
        c.SortIndex = 0;
        c.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
        c.AdaptivePriority = 1;
        c.Settings.AllowHeaderFilter = DefaultBoolean.True;
        c.Settings.AllowAutoFilter = DefaultBoolean.False;
        c.Settings.SortMode = DevExpress.XtraGrid.ColumnSortMode.DisplayText;
        c.SettingsHeaderFilter.Mode = GridHeaderFilterMode.CheckedList;
        c.EditorProperties().ComboBox(cb => {
            cb.DataSource = NorthwindDataProvider.GetCategories();
            cb.TextField = "CategoryName";
            cb.ValueField = "CategoryID";
            cb.ValueType = typeof(int);
        });
    });
}).Bind(Model).GetHtml()
See Also