Dynamically labeling column headers in pivot

Comments

4 comments

  • Avatar
    YourDMS Support

    Hi Jacob - did you ever get a response or devise a solution for this?

    0
    Comment actions Permalink
  • Avatar
    Jacob Gordon

    Hi Joel - Yes, we ended up using javascript to do it. The script looks for particular text (e.g., "LY" for last year) in a given field, based on the field's css class. It then calculates the appropriate date and replaces the text. It's been a while since I set this up, but I believe that most of the javascript was on the forums already.

    0
    Comment actions Permalink
  • Avatar
    Kai Silva

    Hey Jacob - I am looking for the same solution. Trying to dynamically label a pivot table column with the previous month. Could you direct me to the forum post that you're referring to?

    0
    Comment actions Permalink
  • Avatar
    Jacob Gordon
    Hi Kai -

    I'm not sure what post I was following originally, but here's the code that we ended up using.

    dashboard.on("widgetready", function() {
    var e = element;

    //correct CY, LY, and PM to the actual Current Year, Last Year, and Previous Month
    var CY = moment().format("YYYY");
    var LY = moment().subtract(1,"Year").format("YYYY");
    var L2Y = moment().subtract(2,"Year").format("YYYY");
    var PMCY = moment().subtract(1,"Month").format("MMMM");
    var PMLY = moment().subtract(1,"Month").format("MMMM");
    if (PMCY == "December") {
    PMCY = PMCY + ' ' + LY;
    PMLY = PMLY + ' ' + L2Y;
    } else {
    PMCY = PMCY + ' ' + CY;
    PMLY = PMLY + ' ' + LY;
    L2Y = LY;
    }

    $('widget-title').each(function() {
    var text = $(this).text().replace("PMCY", PMCY).replace("PMLY", PMLY).replace("CY", CY).replace("LY", LY).replace("L2Y",L2Y);
    $(this).text(text);
    });


    $('.p-head-content').each(function() {
    var text = $(this).text().replace("PMCY", PMCY).replace("PMLY", PMLY).replace("CY", CY).replace("LY", LY).replace("L2Y",L2Y);
    $(this).text(text);
    });
    });
    0
    Comment actions Permalink

Please sign in to leave a comment.