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

Field options in "All Fields" list in Configuration Panel

8 Answers 199 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 2
Erik asked on 06 Mar 2014, 10:48 PM
I have three key questions regarding the "All Fields" list in the Configuration Panel for RadPivotGrid.

1. For a DateTime field, is it possible to control the options that appear?  I have a DateTime field and the valid values for this field are month beginning dates (e.g. Jan 1 2014, Feb 1 2014, etc).  They drive some monthly reporting that is shown in the PivotGrid.  But in my field chooser I automatically also get Year, Quarter, Month, Week, Day, Hour, Minute, and Second -- which I don't want.  I have searched but can't seem to find a way to suppress them.  Is this possible?  If so, how?

2.  Regarding the rest of the fields -- can I order them how I like after they have been added to the All Fields list (so that the ordering is just shown in the All Fields list)?  I am hoping to be able to sort them alphabetically for easy reference.

3.  If a field exists in a DataTable that is the DataSource for the PivotGrid, is there a way I can exclude that field from the All Fields list?

I think these questions should be pretty straightforward.   If needed, however, I *can* provide a working solution which illustrates them.

Thanks -
Erik Dahl

8 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 11 Mar 2014, 12:37 PM
Hi Erik,

A possible solution to remove a filed from the All Fileds box is to hook FieldCreated event handler and  remove the DataField from the Fields collection of the RadPivotGrid. Please check out the following code snippet.
protected void RadPivotGrid1_FieldCreated(object sender, PivotGridFieldCreatedEventArgs e)
{
    if (e.Field.DataField == "ProductID")
    {
        RadPivotGrid1.Fields.Remove(e.Field);
    }
}
This approach is applicable for the first and the third questions. Regards your second question a possible solution to sort the fields alphabetically is to get the array of all fields on the client and perform a sort operation. For instance, the following code snippet demonstrates how to sort the All Fields items.
<script>
    function pageLoad() {
        var $ = $telerik.$,
            elements = Array.prototype.slice.call($(".rpgFieldsContainer").get(0).childNodes).sort(function (a, b) {
                return a.title > b.title;
            }),
            parent = elements[0].parentNode;
        for (var i = 0; i < elements.length; i++) {
            parent.appendChild(elements[i]);
        }
    }
</script>

Additionally for your convenience I attached the test sample to this forum thread.

Regards,
Kostadin
Telerik

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

0
Erik
Top achievements
Rank 2
answered on 14 Mar 2014, 03:18 PM
This worked great.  I didn't get the javascript to work, but by adding the fields in the appropriate order they show up just fine.

Thanks!
0
Rayko
Top achievements
Rank 1
answered on 23 Mar 2015, 02:02 PM
[quote]Kostadin said:Hi Erik,

A possible solution to remove a filed from the All Fileds box is to hook FieldCreated event handler and  remove the DataField from the Fields collection of the RadPivotGrid. Please check out the following code snippet.
protected void RadPivotGrid1_FieldCreated(object sender, PivotGridFieldCreatedEventArgs e)
{
    if (e.Field.DataField == "ProductID")
    {
        RadPivotGrid1.Fields.Remove(e.Field);
    }
}
 
[/quote]

Hi Kostadin,

It seems that the FieldCreated event doesn't fire for "All fields" collection. When I move a field from "All fields" into another area then the event is fired for this field.
Is there a chance to handle the fields in the "All fields" collection?

Regards,
Rayko
0
Kostadin
Telerik team
answered on 26 Mar 2015, 07:50 AM
Hi Rayko,

I removed all the predefined fields form the RadPivotGrid declaration and on my side the FieldCreated event handler is fired for all fields. Could you please let me know how you are binding the PivotGrid? What is the datasource that you are using.

Regards,
Kostadin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Rayko
Top achievements
Rank 1
answered on 26 Mar 2015, 08:54 AM
Hi Kostadin,

The PivotGrid is bound to an Olap cube via Adomd connection. Initially only the "All fields" box is filled and no FieldCreated event is fired when loading this box.

Regards,
Rayko
0
Kostadin
Telerik team
answered on 30 Mar 2015, 01:36 PM
Hello Rayko,

I am afraid that when binding the PivotGrid to Olap cube the FieldCreated event will not fire. The reason is that the fields are created when you drop them in the appropriate field list and before that you have a TreeView control which contains all the fields. In case you need to access them you can get the RadTreeView control and loop through its item. Please check out the following code snippet.
protected void RadPivotGrid1_PreRender(object sender, EventArgs e)
{
    RadTreeView treeView = RadPivotGrid1.ConfigurationPanel.TreeView;
    for (int i = 0; i < treeView.Nodes.Count; i++)
    {
       string fieldName = treeView.Nodes[i].Text;
    }
}

Regards,
Kostadin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Prasad
Top achievements
Rank 1
answered on 30 Aug 2016, 11:43 PM
How do you delete a node(field) from the above code?
0
Kostadin
Telerik team
answered on 02 Sep 2016, 01:06 PM
Hello,

You can use the Visible property of the node to hide it. Please check out the following code snippet.
protected void RadPivotGrid1_PreRender(object sender, EventArgs e)
{
    RadTreeView treeView = RadPivotGrid1.ConfigurationPanel.TreeView;
    for (int i = 0; i < treeView.Nodes.Count; i++)
    {
        string fieldName = treeView.Nodes[i].Text;
        if (fieldName == "Account")
        {
            treeView.Nodes[i].Visible = false;
        }
 
    }
}


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.
Tags
PivotGrid
Asked by
Erik
Top achievements
Rank 2
Answers by
Kostadin
Telerik team
Erik
Top achievements
Rank 2
Rayko
Top achievements
Rank 1
Prasad
Top achievements
Rank 1
Share this question
or