Pivot Grid PivotGridAggregateField String

9 posts, 0 answers
  1. Syed
    Syed avatar
    36 posts
    Member since:
    Sep 2013

    Posted 03 Dec 2013 Link to this post

    Hi,
    In my project i want to display both String and Numeric values in Pivot Grid PivotGridAggregateField .
    Check the attached Image for more details.
    When i bind String field to PivotGridAggregateField  it shows me error.
    How to display String Field in PivotGridAggregateField .

    <telerik:PivotGridColumnField DataField="Start_Date" Caption="Start_Date" >            
                    </telerik:PivotGridColumnField>
                  

        
                    <telerik:PivotGridRowField DataField="MACHINENAME"  Caption="MACHINENAME" CellStyle-Width="110px"     >
                    </telerik:PivotGridRowField>                      
                 
                    <telerik:PivotGridAggregateField DataField="USER_NM"  Caption="USER_NM"   >
                    <HeaderCellTemplate>User Name</HeaderCellTemplate>
                     
                     </telerik:PivotGridAggregateField>
                  <telerik:PivotGridAggregateField DataField="PROJECT_ID"  Caption="PROJECT_ID"  >
                    <HeaderCellTemplate>PROJECT_ID</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                   <telerik:PivotGridAggregateField DataField="OPER"  Caption="OPER"  >
                     <HeaderCellTemplate>OPER</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                    <telerik:PivotGridAggregateField DataField="Part_NAME"  Caption="Part_NAME"  >
                      <HeaderCellTemplate>Part_NAME</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                     <telerik:PivotGridAggregateField DataField="SUB_LEG_ID"  Caption="SUB_LEG_ID"  >
                       <HeaderCellTemplate>SUB_LEG_ID</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                      <telerik:PivotGridAggregateField DataField="ITEM_NM"  Caption="ITEM_NM"  >
                        <HeaderCellTemplate>ITEM_NM</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                       <telerik:PivotGridAggregateField DataField="OPER_DESCR"  Caption="OPER_DESCR"  >
                         <HeaderCellTemplate>OPER_DESCR</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                        <telerik:PivotGridAggregateField DataField="WORK_NAME"  Caption="WORK_NAME"  >
                          <HeaderCellTemplate>WORK_NAME</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                         <telerik:PivotGridAggregateField DataField="RUN_HRS"  Caption="RUN_HRS"  >
                           <HeaderCellTemplate>RUN_HRS</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                          <telerik:PivotGridAggregateField DataField="MH"  Caption="MH"  > 
                            <HeaderCellTemplate>MH</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>
                            <telerik:PivotGridAggregateField DataField="MCH"  Caption="MCH"  >
                              <HeaderCellTemplate>MCH</HeaderCellTemplate>
                     </telerik:PivotGridAggregateField>

    This works fine but i want to display the Strings in Aggregate field.
    How to resolve this.

  2. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 05 Dec 2013 Link to this post

    Hi Syed,

    Basically PivotGrid table is created to work with numeric data and setting a string data will lead to an Error text in the cell. Nevertheless you could display any kind of content by using the templates. Please check out the following live example which demonstrates the use them.

    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Syed
    Syed avatar
    36 posts
    Member since:
    Sep 2013

    Posted 05 Dec 2013 Link to this post

    Hi,
    Thanks for your reply.
    I have used Cell template in Aggregate field  and used the Container.DataItem in aggregate field but it doesnt display the data in aggregate field only error display in that place.
     <telerik:PivotGridAggregateField DataField="USER_NM"  Caption="user"  CellStyle-Width="80px" >
                    <HeaderCellTemplate>작업자</HeaderCellTemplate>
                      <celltemplate>
                          <asp:Label ID="lblUSER_NM" runat="server" Text=  <%# Container.DataItem   %>>                      
                            </asp:Label>
                          </celltemplate>
                     </telerik:PivotGridAggregateField>
    How to get string field using cell template at  Aggregate field.
    But now as my solution in cell data bound i get the data from grid datasource and assign the values.
    In Cell data Bound

      if (e.Cell is PivotGridDataCell)
            {

                e.Cell.HorizontalAlign = HorizontalAlign.Left;

                PivotGridDataCell cell = e.Cell as PivotGridDataCell;

                if (cell.CellType == PivotGridDataCellType.DataCell)
                {
                    String rowVal = cell.ParentRowIndexes[1].ToString();

                    DataSet ds = (DataSet)RadPivotGrid1.DataSource;

                    DataView dv = new DataView(ds.Tables[0]);
                    dv.RowFilter = "Row ='" + rowVal + "'";

                    if (cell != null)
                    {
                        switch ((cell.Field as PivotGridAggregateField).DataField)
                        {
                            case "USER_NM":
                                Label lblUSER_NM = cell.FindControl("lblUSER_NM") as Label;
                                if (lblUSER_NM != null)
                                {
                                    if (lblUSER_NM.Text != null)
                                    {                                 
                                        lblUSER_NM.Text = dv[0]["USER_NM"].ToString();
                                      
                                    }
                                }
                                break;


                            }
                        } } }

    If there is simple option to display string in aggregate field it will be more good for performance wise.
  5. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 10 Dec 2013 Link to this post

    Hello Syed,

    I am afraid that this is the only possible way to display a string into the cell. For your convenience I prepared a small sample and attached it to this thread. Please give it a try and let me know how it differs from your real setup.

    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
  6. Syed
    Syed avatar
    36 posts
    Member since:
    Sep 2013

    Posted 11 Dec 2013 Link to this post

    Hi,
    Thanks for your response.
    I have used the same method to display String in a Aggregate Filed.
  7. Syed
    Syed avatar
    36 posts
    Member since:
    Sep 2013

    Posted 11 Dec 2013 Link to this post

    I have one more question.
    In  PivotGridRowField  the Width is not matching .Here i have used your same sample program .Row Datafield="Color" i set with=50px
    and for the Row Datafield="Line" i set with=120px.
    But when i run the program the width is missmatching see the attached image file.

    <telerik:PivotGridRowField DataField="Color" ShowGroupsWhenNoData="true" UniqueName="Color" CellStyle-Width="50px">
                    </telerik:PivotGridRowField>
                    <telerik:PivotGridRowField DataField="Line" UniqueName="Line" CellStyle-Width="120px">
                    </telerik:PivotGridRowField>

    You can see in the image Color Field width is matched to Line Field .
  8. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 13 Dec 2013 Link to this post

    Hello Syed,

    By setting cell width you are actually set a width if the Color and Line buttons which are used to filter and sort the appropriate data. You could noticed that in the image which you have provided that part of the Color button is hidden due to the small size of the width.

    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
  9. Syed
    Syed avatar
    36 posts
    Member since:
    Sep 2013

    Posted 15 Dec 2013 Link to this post

    How can we set the fixed with for each rowfield columns.
  10. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 19 Dec 2013 Link to this post

    Hello Syed,

    You could set a width of the PivotGrid HeaderCells by using RowHeaderCellStyle and ColumnHeaderCellStyle. Please check out the following code snippet.
    <telerik:RadPivotGrid AllowFiltering="true" OnNeedDataSource="RadPivotGrid1_NeedDataSource"
      runat="server">
       <RowHeaderCellStyle Width="100px" Height="15px" />
       <ColumnHeaderCellStyle Width="100px" Height="15px" />


    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017