Back to Devexpress

CardViewColumn.SortIndex Property

aspnet-devexpress-dot-web-dot-cardviewcolumn-da065918.md

latest5.5 KB
Original Source

CardViewColumn.SortIndex Property

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

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

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

Property Value

TypeDefaultDescription
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 ASPxCardView 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 cards.

Setting the SortIndex property to a non-negative integer, the column is added to the sorted columns list. The column’s CardViewColumn.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 code sample below demonstrates how to focus a newly inserted card. Handle the CardInserted event to get a key value of the card. Call the FindVisibleIndexByKeyValue(Object) method to get the card’s visible index. Then set the FocusedCardIndex property.

aspx
<dx:ASPxCardView ID="ASPxCardView1" runat="server" AutoGenerateColumns="False" DataSourceID="XpoDataSource1" 
    KeyFieldName="Oid" OnCardInserted="ASPxCardView1_CardInserted">
    <SettingsPager>
        <SettingsTableLayout ColumnCount="2" RowsPerPage="2" />
    </SettingsPager>
    <SettingsBehavior AllowFocusedCard="True" />
    <Columns>
        <dx:CardViewTextColumn FieldName="Oid" ReadOnly="True" 
            SortIndex="0" SortOrder="Ascending" Visible="False" />
        <dx:CardViewTextColumn FieldName="CompanyName" />
        <dx:CardViewTextColumn FieldName="ContactName" />
        <dx:CardViewTextColumn FieldName="Country" />
    </Columns>
    <CardLayoutProperties>
        <Items>
            <dx:CardViewCommandLayoutItem HorizontalAlign="Right" ShowEditButton="True" ShowNewButton="True" />
            <dx:CardViewColumnLayoutItem ColumnName="Oid" />
            <dx:CardViewColumnLayoutItem ColumnName="Company Name" />
            <dx:CardViewColumnLayoutItem ColumnName="Contact Name" />
            <dx:CardViewColumnLayoutItem ColumnName="Country" />
            <dx:EditModeCommandLayoutItem HorizontalAlign="Right" />
        </Items>
    </CardLayoutProperties>
</dx:ASPxCardView>
csharp
protected void ASPxCardView1_CardInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e) {
    object newKey = null;
    if (e.AffectedRecords == 1)
    {
        ICollection objects = uof.GetObjectsToSave();
        if (objects != null && objects.Count == 1)
        {
            IEnumerator enumeration = objects.GetEnumerator();
            enumeration.MoveNext();
            Customer obj = (Customer)enumeration.Current;
            uof.CommitChanges();
            newKey = obj.Oid;
        }
    }
    ASPxCardView1.FocusedCardIndex = ASPxCardView1.FindVisibleIndexByKeyValue(newKey);
}
vb
Protected Sub ASPxCardView1_CardInserted(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataInsertedEventArgs)
    Dim newKey As Object = Nothing
    If e.AffectedRecords = 1 Then
        Dim objects As ICollection = uof.GetObjectsToSave()
        If objects IsNot Nothing AndAlso objects.Count = 1 Then
            Dim enumeration As IEnumerator = objects.GetEnumerator()
            enumeration.MoveNext()
            Dim obj As Customer = DirectCast(enumeration.Current, Customer)
            uof.CommitChanges()
            newKey = obj.Oid
        End If
    End If
    ASPxCardView1.FocusedCardIndex = ASPxCardView1.FindVisibleIndexByKeyValue(newKey)
End Sub

See Also

SortOrder

AllowSort

Card View

CardViewColumn Class

CardViewColumn Members

DevExpress.Web Namespace