Field options in "All Fields" list in Configuration Panel

10 posts, 1 answers
  1. Erik
    Erik avatar
    43 posts
    Member since:
    Jan 2011

    Posted 06 Mar 2014 Link to this post

    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
  2. Answer
    Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 11 Mar 2014 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Erik
    Erik avatar
    43 posts
    Member since:
    Jan 2011

    Posted 14 Mar 2014 in reply to Kostadin Link to this post

    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!
  5. Rayko
    Rayko avatar
    27 posts
    Member since:
    Jul 2012

    Posted 23 Mar 2015 in reply to Kostadin Link to this post

    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);
        }
    }
     


    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
  6. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 26 Mar 2015 Link to this post

    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.

     
  7. Rayko
    Rayko avatar
    27 posts
    Member since:
    Jul 2012

    Posted 26 Mar 2015 in reply to Kostadin Link to this post

    Hi Kostadin,

    The PivotGrid is bound to a 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
  8. Rayko
    Rayko avatar
    27 posts
    Member since:
    Jul 2012

    Posted 26 Mar 2015 in reply to Kostadin Link to this post

    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
  9. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 30 Mar 2015 Link to this post

    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.

     
  10. Prasad
    Prasad avatar
    2 posts
    Member since:
    Jul 2016

    Posted 30 Aug in reply to Kostadin Link to this post

    How do you delete a node(field) from the above code?
  11. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 02 Sep Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017