RadGrid Drag&Drop and Grouping

4 posts, 0 answers
  1. Saltug
    Saltug avatar
    3 posts
    Member since:
    Jul 2010

    Posted 26 May 2011 Link to this post

    Hello All,

    I want to make a Gridview with a default grouping. For example i have 2 tables. The first one includes Countries and Country IDs. The second contains ID, ContactName, Email, CountryID.

    I have 3 Country record in my Countries table and 5 Contact record in my Contacts table. 3 of my contacts belong to CountryID 1 and 2 of them to CountryID 2. There is no contacts for CountryID 3.

    I want to group my grid by countries and show all the 3 country and contacts below.

    The second condition is i want to be able to move this contacts between this groups. (Of course the records will be updated)

    A sample view of my finish work is attached. I get all my countries by grouping in SQL Query. Bu the mistake is i get 1 record for the empty Country record. It souldnt.

    My SQL Query is like:

    SELECT Contacts.ID, Contacts.ContactName, Contacts.Email, Countries.ID AS CountryID, Countries.CountryName, COUNT(Contacts.ID) AS TotalContacts

    FROM Contacts RIGHT OUTER JOIN Countries ON Contacts.CountryID = Countries.ID

    GROUP BY Contacts.CountryID, Countries.ID, Countries.CountryName, Contacts.ContactName, Contacts.Email, Contacts.ID

    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlData"
        AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False"
        AllowPaging="True" PageSize="15" GridLines="None" OnRowDrop="RadGrid1_RowDrop">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <MasterTableView DataSourceID="SqlData" DataKeyNames="ID" GroupLoadMode="Server">
            <GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <SelectFields>
                        <telerik:GridGroupByField FieldAlias="Country" FieldName="Country"></telerik:GridGroupByField>
                        <telerik:GridGroupByField FieldName="TotalContact" Aggregate="Count"></telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldName="Country"></telerik:GridGroupByField>
                    </GroupByFields>
                </telerik:GridGroupByExpression>
            </GroupByExpressions>
            <Columns>
                <telerik:GridDragDropColumn HeaderStyle-Width="18px" />
                <telerik:GridBoundColumn SortExpression="ID" HeaderText="ID" HeaderButtonType="TextButton" datafield="ID" UniqueName="ID" />
                <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Name" HeaderButtonType="TextButton" datafield="ContactName" UniqueName="ContactName" />
                <telerik:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton" DataField="Country" UniqueName="Country" />
            </Columns>
        </MasterTableView>
        <ClientSettings AllowRowsDragDrop="true"
           <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" /> 
        </ClientSettings>
    </telerik:RadGrid>
  2. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 30 May 2011 Link to this post

    Hi Saltug,

     You do not need to specify a separate group query in your SqlDataSource. The grid will group the items automatically if it has the proper group settings as in your case. Live demo of the grouping features of the grid is available here.

    All the best,
    Marin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Saltug
    Saltug avatar
    3 posts
    Member since:
    Jul 2010

    Posted 30 May 2011 Link to this post


    Hello again,

    Can i get the data from different queries or data sources for grouping and for the grouped data. Then if there is an ungrouped data, it sould be shown as ungrouped.
  5. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 31 May 2011 Link to this post

    Hi Saltug,

     When you have a group by clause in the query each record is distributed to some group hence you do not have an ungrouped data. I see in the query that the first two fields that you group by are IDs so every record that has CountryID or ID will be put in a separate group initially and then the SQL server will try to make another groups by CountryName, ContactName and so on. Additionally you have right outer join which might result in records for countries that do not have contacts (like the item for Istanbul in the screenshot) to avoid such empty records you might try the inner join clause.
    The datasource for the grid can contain only one query and it should not contain group by clause because the grid will try to additionally group the already grouped data that is passed.
    My advice is to remove the group by clause from the query and use only the GridGroupByExpressions of the MasterTableView to specify groups for the grid.

    Regards,
    Marin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top