Adding subtotals to OLAP grid programmatically

Posted by: liviu01 on 9 September 2017, 8:29 am EST

  • Posted 9 September 2017, 8:29 am EST

    I am trying to create a custom C1OlapPage grid programmatically. I followed the steps from your documentation and it worked properly, but now I need to add subtotals. I found how to add the total field (olap.ValueFields.Add("Sales");) and how to change the format and functions of the existing subtotals (field = olap.Fields["Sales"]; field.Format = "c"; field.Subtotal = Subtotal.Average;), but I didn't find anywhere how to activate/add the subtotals for some of my fields, as is possible to achieve through UI from Grid -> Total Rows -> Subtotals.
    Is it possible to achieve this programmatically? Any help will be appreciated.
    Thanks!
  • Replied 9 September 2017, 8:29 am EST

    Liviu01,

    You will need to set the ShowTotalRows property to Subtotals in code behind to get the desired results. Please find the code snippet below which sets the SubTotals on a Click of a button.


    using System;
    using System.Linq;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Collections.Generic;
    using Microsoft.LightSwitch;
    using Microsoft.LightSwitch.Framework.Client;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Extensions;
    using C1.Silverlight.Olap;
    using Microsoft.LightSwitch.Threading;
    namespace LightSwitchApplication
    {
    public partial class OlapViewDefinition
    {
    C1OlapPage Olp = new C1OlapPage();
    partial void SubTotal_Execute()
    {


    Dispatchers.Main.BeginInvoke(() =>
    {

    var olap = Olp.OlapEngine;

    olap.BeginUpdate();

    olap.ShowTotalsRows = C1.Olap.ShowTotals.Subtotals;
    olap.EndUpdate();
    });


    }

    partial void OlapViewDefinition_Created()
    {
    IContentItemProxy gridProxy = this.FindControl("C1OlapPage");
    gridProxy.ControlAvailable += gridProxy_ControlAvailable;

    }

    void gridProxy_ControlAvailable(object sender, ControlAvailableEventArgs e)
    {
    Olp = (C1OlapPage)e.Control;

    }
    }
    }



    Best Regards,
    Abhishek
  • Replied 9 September 2017, 8:29 am EST

    Thank you very much for your help Abhishek.

    Have a nice day!
  • Replied 9 September 2017, 8:29 am EST

    One more question if you don't mind. Is it possible to show the subtotal just for a certain field and not for all?
  • Replied 9 September 2017, 8:29 am EST

    Liviu01,

    Unfortunately , it is not possible to show subtotals only for certain fields with the current implementation .

    Best Regards,
    Abhishek
  • Replied 9 September 2017, 8:29 am EST

    Too bad... it would be nice to have this feature. Thank you again for your fast reply Abhishek.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels