This is a migrated thread and some comments may be shown as answers.

2 GridDropDownColumn on same datasource - only one column sorts

1 Answer 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 24 Feb 2021, 05:10 AM

Hi there.

I have a radgrid that has two GridDropDownColumns both using the same datasource to display a list of users.

When I click the second column header it sorts the first column. I.e. I clicked the Overseer column below but it sorted the Author column.

<telerik:GridDropDownColumn AllowFiltering="false" AllowAutomaticLoadOnDemand="true" DropDownControlType="RadComboBox" DataField="ProcessAuthorUserID" DataType="System.Int32" HeaderText="Author" HeaderStyle-Width="110px" SortExpression="DisplayName" UniqueName="ProcessAuthorUserID" DataSourceID="SqlDataSource2" ListTextField="DisplayName" ListValueField="UserID">
    <ItemStyle VerticalAlign="top" Width="60px" />
</telerik:GridDropDownColumn>
<telerik:GridDropDownColumn AllowFiltering="false" AllowAutomaticLoadOnDemand="true" DropDownControlType="RadComboBox" DataField="DOUserID" DataType="System.Int32" HeaderText="Overseer" HeaderStyle-Width="110px" SortExpression="DisplayName" UniqueName="DOUserID" DataSourceID="SqlDataSource2" ListTextField="DisplayName" ListValueField="UserID">
    <ItemStyle VerticalAlign="top" Width="60px" />
</telerik:GridDropDownColumn>

 

Thanks in advance. :-)

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 26 Feb 2021, 02:49 PM

Hi Chris,

Normally, when the SortExpression of multiple columns is the same, all of those columns will be sorted upon sorting one.

Example

 

If the sorting happens to one column only, then there must be some additional logic Server or Client that changes that or have some specific settings for the Grid that could actually be the culprit. We would need to see that before suggesting anything specific. Share the complete grid declaration and all server-side code that is used by it. We can check and see if a custom code interferes or it is a bug in the source.

Here is the complete code I used in my example:

Default.aspx

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" >
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID">
        <Columns>
            <telerik:GridDateTimeColumn DataField="OrderDate" DataType="System.DateTime"
                FilterControlAltText="Filter OrderDate column" HeaderText="OrderDate"
                SortExpression="OrderDate" UniqueName="OrderDate">
            </telerik:GridDateTimeColumn>
            <telerik:GridNumericColumn DataField="Freight" DataType="System.Decimal"
                FilterControlAltText="Filter Freight column" HeaderText="Freight"
                SortExpression="Freight" UniqueName="Freight">
            </telerik:GridNumericColumn>

            <telerik:GridDropDownColumn DataField="ShipName" HeaderText="Author" ListTextField="ShipName" ListValueField="ShipName" ListDataMember="ShipName" SortExpression="OrderID">
            </telerik:GridDropDownColumn>
            <telerik:GridDropDownColumn DataField="ShipCountry" HeaderText="Overseer" ListTextField="ShipCountry" ListValueField="ShipCountry" ListDataMember="ShipCountry" SortExpression="OrderID">
            </telerik:GridDropDownColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

 

Default.aspx.cs

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = OrdersTable(); 
}

private DataTable OrdersTable()
{
    DataTable dt = new DataTable();

    dt.Columns.Add(new DataColumn("OrderID", typeof(int)));
    dt.Columns.Add(new DataColumn("OrderDate", typeof(DateTime)));
    dt.Columns.Add(new DataColumn("Freight", typeof(decimal)));
    dt.Columns.Add(new DataColumn("ShipName", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry", typeof(string)));

    dt.PrimaryKey = new DataColumn[] { dt.Columns["OrderID"] };

    for (int i = 0; i < 70; i++)
    {
        int index = i + 1;

        DataRow row = dt.NewRow();

        row["OrderID"] = index;
        row["OrderDate"] = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).AddHours(index);
        row["Freight"] = index * 0.1 + index * 0.01;
        row["ShipName"] = "Name " + index;
        row["ShipCountry"] = "Country " + index;

        dt.Rows.Add(row);
    }

    return dt;
}

 

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or