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

Pivot Grid PivotGridAggregateField String

8 Answers 390 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Syed
Top achievements
Rank 1
Syed asked on 03 Dec 2013, 09:09 AM
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.

8 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 05 Dec 2013, 11:01 AM
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.
0
Syed
Top achievements
Rank 1
answered on 05 Dec 2013, 11:50 PM
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.
0
Kostadin
Telerik team
answered on 10 Dec 2013, 02:45 PM
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.
0
Syed
Top achievements
Rank 1
answered on 11 Dec 2013, 08:35 AM
Hi,
Thanks for your response.
I have used the same method to display String in a Aggregate Filed.
0
Syed
Top achievements
Rank 1
answered on 11 Dec 2013, 08:49 AM
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 .
0
Kostadin
Telerik team
answered on 13 Dec 2013, 02:31 PM
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.
0
Syed
Top achievements
Rank 1
answered on 16 Dec 2013, 01:23 AM
How can we set the fixed with for each rowfield columns.
0
Kostadin
Telerik team
answered on 19 Dec 2013, 08:25 AM
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.
Tags
PivotGrid
Asked by
Syed
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Syed
Top achievements
Rank 1
Share this question
or