GroupByExpressions and SortExpressions

15 posts, 1 answers
  1. Adrian Barnes
    Adrian Barnes avatar
    18 posts
    Member since:
    Dec 2009

    Posted 03 Apr 2013 Link to this post

    I'm apparently missing something here.  Trying to change the sort order of a grid that uses GroupByExpressions with no luck.

    I started with the following:
    <GroupByExpressions>
        <telerik:GridGroupByExpression>
            <GroupByFields>
                <telerik:GridGroupByField FieldName="OrderID" />
            </GroupByFields>
            <SelectFields>
                <telerik:GridGroupByField FieldName="OrderID" HeaderText="Order ID" />
                <telerik:GridGroupByField FieldName="CustLastFirst" HeaderText="Customer" />
                <telerik:GridGroupByField FieldName="Total" HeaderText="Order Total" FormatString="{0:C}" />
            </SelectFields>
        </telerik:GridGroupByExpression>
    </GroupByExpressions>


    Then I tried adding this:
    <SortExpressions>
        <telerik:GridSortExpression FieldName="CustLastFirst" SortOrder="Ascending" />
    </SortExpressions>

    And I tried variations of this, but get either no action or a type mismatch error:
    <GroupByFields>
        <telerik:GridGroupByField FieldName="OrderID" />
        <telerik:GridGroupByField FieldName="CustLastFirst" />
    </GroupByFields>


    Any suggestions?  Thanks!


  2. Adrian Barnes
    Adrian Barnes avatar
    18 posts
    Member since:
    Dec 2009

    Posted 04 Apr 2013 Link to this post

    Should I just open a support ticket?  Thx.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Apr 2013 Link to this post

    Hi,

    You can specify SortOrder  in the GroupByFields collection as shown below.

    aspx:
    <GroupByFields>
        <telerik:GridGroupByField FieldName="OrderID" />
        <telerik:GridGroupByField FieldName="CustLastFirst" SortOrder="Descending" />
    </GroupByFields>

    Thanks,
    Princy
  5. Adrian Barnes
    Adrian Barnes avatar
    18 posts
    Member since:
    Dec 2009

    Posted 05 Apr 2013 Link to this post

    Thanks for the response! Unfortunately, as indicated in my original post, when I add "CustLastFirst" to the GroupByFields,  I get an  error ("Operator '=' incompatible with operand types 'Object' and 'Int32'").

    <GroupByExpressions>
        <telerik:GridGroupByExpression>
            <GroupByFields>
                <telerik:GridGroupByField FieldName="OrderID" />
                <telerik:GridGroupByField FieldName="CustLastFirst" SortOrder="Descending" />
            </GroupByFields>
            <SelectFields>
                <telerik:GridGroupByField FieldName="OrderID" HeaderText="Order ID" />
                <telerik:GridGroupByField FieldName="CustLastFirst" HeaderText="Customer" />
                <telerik:GridGroupByField FieldName="Total" HeaderText="Order Total" FormatString="{0:C}" />
            </SelectFields>
        </telerik:GridGroupByExpression>
    </GroupByExpressions>

  6. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 08 Apr 2013 Link to this post

    Hi Adrian,

    Could you please elaborate a little bit more on your scenario? What kind of data source you are using? It would be best if you could provide us with your code declaration and the related code behind.
    I tried to replicate the issue on my side but to no avail. I prepared a small sample and attached it to this forum post. Please give it a try and let me know how it differs from your real setup.

    All the best,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Adrian Barnes
    Adrian Barnes avatar
    18 posts
    Member since:
    Dec 2009

    Posted 08 Apr 2013 Link to this post

    Thanks for the response.  I will take a look at the code you sent.  I am binding to a simple dataset created from a call to stored procedures.  I will include my entire grid declaration and the code that binds data to it.  I'm actually binding to three grids, but two of them are identical (rdgOrderDetails and rdgExpiredOrderDetails) and each shows a different set of data.  Both of those are having the same problem.

    If I wrap the Databind() code in a Try..Catch block, the grid renders just fine with all data intact, but without the sorting.

    private void FillSummaryGrid()
    {
        string sql = "";
        string errString = "";
        DataSet ds;
     
        sql = "EXEC GetOrderFulfillmentSummaryNew " + cboPickup.SelectedItem.Value;
        sql += "; EXEC GetOrderFulfillmentDetailsNotExpired " + cboPickup.SelectedItem.Value;
        sql += "; EXEC GetOrderFulfillmentDetailsExpired " + cboPickup.SelectedItem.Value + "; ";
     
        ds = PageData.GetData(sql, ref errString);
     
        rdgOrderDetails.DataSource = ds.Tables[1];
        rdgOrderDetails.DataBind();
     
        rdgExpiredOrderDetails.DataSource = ds.Tables[2];
        rdgExpiredOrderDetails.DataBind();
     
    }



    And here is the grid.  All of the functions called from the grid are public and expect parameters to be passed as "object."  I've looked at those functions and they aren't throwing any errors.


    <telerik:RadGrid runat="server" ID="rdgOrderDetails" AutoGenerateColumns="false"
        Width="1100px" Skin="WebBlue" Font-Size="XX-Small"
        AllowAutomaticInserts="false" AllowAutomaticUpdates="false" ShowFooter="true">
        <MasterTableView DataKeyNames="OrderID" AllowAutomaticInserts="false" AllowAutomaticUpdates="false" CommandItemDisplay="None" CommandItemSettings-ShowRefreshButton="false">
            <Columns>
                <telerik:GridTemplateColumn runat="server" HeaderText="Customer">
                    <ItemTemplate>
                        <%# GetCurrentOrderURL(DataBinder.Eval(Container.DataItem, "OrderID"))%>
                        <a href='CustomerEdit.aspx?cid=<%# DataBinder.Eval(Container.DataItem, "CustomerID")%>' target="_blank"><%# GetCustomerName(DataBinder.Eval(Container.DataItem, "FirstName"), DataBinder.Eval(Container.DataItem, "LastName"))%></a>
                        <%# GetEmail(DataBinder.Eval(Container.DataItem, "Email"))%>
                        <%# GetPhone(DataBinder.Eval(Container.DataItem, "Phone"))%>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn runat="server" HeaderText="Subscr<br>Status" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right">
                    <ItemTemplate>
                        <%# GetSubscriptionStatus(DataBinder.Eval(Container.DataItem, "SubscriptionID"))%>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn runat="server" HeaderText="CustID">
                    <ItemTemplate>
                        <%# GetCustomerID(DataBinder.Eval(Container.DataItem, "CustomerID"))%>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn runat="server" HeaderText="OrderID">
                    <ItemTemplate>
                        <%# GetOrderID(DataBinder.Eval(Container.DataItem, "OrderID"))%>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="ItemID" HeaderText="ItemID"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Quantity" HeaderText="Qty" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" Aggregate="Sum" FooterText="Items Ordered : " FooterStyle-HorizontalAlign="Right"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Price" DataFormatString="{0:C}" HeaderText="Price"></telerik:GridBoundColumn>
                <telerik:GridCalculatedColumn HeaderText="Line Total" UniqueName="TotalPrice" DataType="System.Double" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
                 DataFields="DecQuantity, DecWeight, Price" Expression="({0}*{1})*{2}" FooterText="Total : " Aggregate="Sum" DataFormatString="{0:C}" />
     
            </Columns>
     
            <SortExpressions>
                <telerik:GridSortExpression FieldName="LastName" SortOrder="Ascending" />
            </SortExpressions>
            <GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldName="OrderID" />
                    </GroupByFields>
                    <SelectFields>
                        <telerik:GridGroupByField FieldName="OrderID" HeaderText="Order ID" />
                        <telerik:GridGroupByField FieldName="CustLastFirst" HeaderText="Customer" />
                        <telerik:GridGroupByField FieldName="Total" HeaderText="Order Total" FormatString="{0:C}" />
                    </SelectFields>
                </telerik:GridGroupByExpression>
            </GroupByExpressions>
        </MasterTableView>
    </telerik:RadGrid>


  8. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 11 Apr 2013 Link to this post

    Hello Adrian,

    I would suggest you to use advanced data binding instead simple data binding. Please give this approach a try and let me know about the result.

    All the best,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Adrian Barnes
    Adrian Barnes avatar
    18 posts
    Member since:
    Dec 2009

    Posted 15 Apr 2013 Link to this post

    Thanks for the idea, but that didn't make any difference.  The data is coming out of the database in the right order, but somehow the grouping I have going on within the grid is not allowing any of the sorts to work.  Below is the latest iteration that doesn't work.  If I reverse the order of the <GroupByFields> I get the error message mentioned earlier.

    <GroupByExpressions>
        <telerik:GridGroupByExpression>
            <GroupByFields>
                <telerik:GridGroupByField FieldName="OrderID" />
                <telerik:GridGroupByField FieldName="CustLastFirst" SortOrder="Ascending" />
            </GroupByFields>
            <SelectFields>
                <telerik:GridGroupByField FieldName="CustLastFirst" HeaderText="Customer" SortOrder="Ascending" />
                <telerik:GridGroupByField FieldName="OrderID" HeaderText="Order ID" />
                <telerik:GridGroupByField FieldName="Total" HeaderText="Order Total" FormatString="{0:C}" />
            </SelectFields>
        </telerik:GridGroupByExpression>
    </GroupByExpressions>

  10. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 18 Apr 2013 Link to this post

    Hello Adrian,

    I am afraid without running sample it will be hard to pinpoint the reason for that behavior. Could you please provide us with a small runnable sample or replicate the issue in the sample from my previous post in order to observe the issue locally ?

    Kind regards,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  11. Adrian Barnes
    Adrian Barnes avatar
    18 posts
    Member since:
    Dec 2009

    Posted 18 Apr 2013 Link to this post

    After looking at your example and getting nowhere, I decided to start dismantling my grid.  Turns out the error is happening because of this column:

    <telerik:GridCalculatedColumn HeaderText="Line Total" UniqueName="TotalPrice" DataType="System.Double" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
                                     DataFields="DecQuantity, DecWeight, Price" Expression="({0}*{1})*{2}" FooterText="Total : " Aggregate="Sum" DataFormatString="{0:C}" />

    Why would a summary/calculated column throw an error when the sorting changes?  Once again, the error message is:

    Operator '=' incompatible with operand types 'Object' and 'Int32'



  12. Answer
    Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 23 Apr 2013 Link to this post

    Hi Adrian,

    Can you please check whether setting the EnableLinqExpressions property of the RadGrid instance to false addressed the error you receive? Thus you will force the grid to use the old filter expression comparison and everything should be fine with your Classic implementation.
    <telerik:RadGrid ID="RadGrid1" runat="server" EnableLinqExpressions="false">

    If you still experience the same behavior, could you please provide us with your code declaration and the related code behind in order to investigate the issue further.

    Kind regards,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  13. Adrian Barnes
    Adrian Barnes avatar
    18 posts
    Member since:
    Dec 2009

    Posted 23 Apr 2013 Link to this post

    Kostadin,

    Thanks!  That fixed the problem.  What do you mean by "the old filter comparison method?"  I put together this particular grid using examples on Telerik's site (for the calculated columns, grouping, and such).  Did I do something the wrong way?  I do not use LINQ on purpose.  Is that it?

    Thanks!
    Adrian
  14. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 26 Apr 2013 Link to this post

    Hello Adrian,

    The differences is that when EnableLinqExpressions is enabled the ongoing operations are using linq, otherwise they are using .NET 2.0 approach.

    Greetings,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  15. Erik
    Erik avatar
    3 posts
    Member since:
    Sep 2015

    Posted 26 Sep in reply to Kostadin Link to this post

    I am running into this issue as well. Do you have any plans to fix this bug? Looks like it's been about 2 years
  16. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 29 Sep Link to this post

    Hi Erik,

    I tried to replicate the issue on my end but to no avail. Could you please check out the attached sample and let me know how it differs from your real setup? I would appreciate if you can share more details about the grid configuration and the dataosource which is using.

    Regards,
    Kostadin
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017