Style Pivot Column Base on Another Column

Comments

8 comments

  • Avatar
    Eli

    Script was updated: removed WIDGET_ID 

    0
    Comment actions Permalink
  • Avatar
    Hila Kantor

    Use the following script in order to change the column style based on 2 criterias:

    widget.on("ready", function(widget, args) {
                                   
                                                    var CUR_COL_FIND_CRITERIA_red = "[fidx=5]";
                                                    var CUR_COL_FIND_CRITERIA_green = "[fidx=6]";
                                                    var FORMAT_COL_FIND_CRITERIA = "[fidx=4]";
                                   
                                                    //format a cell according to a condition on the current cell
                                                    function formatCell(){
                                                                    if ($(this).attr('val') <= $(this).siblings(CUR_COL_FIND_CRITERIA_red).attr('val')){
                                                                                    $(this).css("color", "red");
                                                                    }
                                                                    else if($(this).attr('val') <= $(this).siblings(CUR_COL_FIND_CRITERIA_green).attr('val')){
                                                                                    $(this).css("color", "green");
                                                                   
                                                                    }
                                                    }
     
                                                    //get all column cells and format other cells
                                                    var cells = $('[id="' + widget.oid+ '"]').find('td' + FORMAT_COL_FIND_CRITERIA).each(formatCell);
     
                                                    //hide current column and set new width for the pivots
                                                    $('[id="' + widget.oid+ '"]').find(CUR_COL_FIND_CRITERIA_red).html("");
                                                    $('[id="' + widget.oid+ '"]').find(CUR_COL_FIND_CRITERIA_red).css("width", "0px");
                                                    $('[id="' + widget.oid+ '"]').find(CUR_COL_FIND_CRITERIA_green).html("");
                                                    $('[id="' + widget.oid+ '"]').find(CUR_COL_FIND_CRITERIA_green).css("width", "0px");
                    });
    0
    Comment actions Permalink
  • Avatar
    Aviad Harell

    Cool post, you could also use this script to sort a table by a hidden value

    1
    Comment actions Permalink
  • Avatar
    Rachel Wijsmuller

    Cool modification, however I now can't filter with a *ranking* on the formatted column... 

    0
    Comment actions Permalink
  • Avatar
    Robert Choquette

    To sort by a hidden value (1st column) you can use this script.

    /********************************************************/
    /*Style pivot column based on another pivot column*******/
    /********************************************************/

    // Ensure that the sort column is the first one, and the visible column is the second one

    widget.on("ready", function(widget, args) {

    var CUR_COL_FIND_CRITERIA = "[fidx=0]";
    var FORMAT_COL_FIND_CRITERIA = "[fidx=1]";

    //hide current column and set new width for the pivots
    $('[id="' + widget.oid+ '"]').find(CUR_COL_FIND_CRITERIA).html("");
    $('[id="' + widget.oid+ '"]').find(CUR_COL_FIND_CRITERIA).css("width", "1px");
    });

    Note that I modified the css width to be 1px instead of 0.  Using 0 didn't hide the column but made the contents appear blank.

    2
    Comment actions Permalink
  • Avatar
    Carla Herrera

    Does this only work for numeric values? Can the formatted column be text?

    0
    Comment actions Permalink
  • Avatar
    Robert Choquette

    It should work the same regardless of the type of value.

    0
    Comment actions Permalink
  • Avatar
    Oxana Noa Umansky

    Thanks so much for sharing Robert!

    0
    Comment actions Permalink

Please sign in to leave a comment.