Conditional Formatting a View in Power Portal using Javascript

 Hi Readers,

Conditional formatting in Power Portals allows you to dynamically style or format rows in a view based on certain criteria. Here's a step-by-step guide on how to achieve this.

  • In the Power Apps Maker portal, navigate to the web page where you want to condition formatting.







  • Open Entity for Add hyperlink into "Options" tab.














  • Update Javascript as mentioned below in "Custom/javascript" box
$(document).ready(function (){
    var entityList = $(".entitylist.entity-grid").eq(0);
    entityList.on("loaded", function () {
        entityList.find("table tbody > tr").each(function (index, tr) {
            var td = $(tr).find('td[data-attribute="statecode"]');
            var primaryColumn = $(tr).find('td[data-attribute="statecode"]').text();
            if(primaryColumn == "Fulfilled")
            {
               
                $(td).css("background-color", "#E1FCEF");
                $(td).css("color", "green");
            }
            if(primaryColumn == "Active")
            {
                $(td).css("background-color", "#BBDEF4");
                $(td).css("color", "#284198");//#3F74C6
            }
            if(primaryColumn == "Submitted")
            {
                $(td).css("background-color", "#FCF2E6");
                $(td).css("color", "#C97A20");
            }
            if(primaryColumn == "Canceled")
            {
                $(td).css("background-color", "#E9EDF5");
                $(td).css("color", "#43454A");
            }
            if(primaryColumn == "Invoiced")
            {
                $(td).css("background-color", "#BC8F8F");
                $(td).css("color", "#191970");
            }
           
        });
    });
});

Note: Change data attribute and value for the text.

Save the changes to the web page.

If you add some CSS like below it's very useful.

[data-attribute="statecode"]
{
    text-align: center;
    display: flex;
    width: 85px;
    height: 23px;
    border-radius: 6px;
    flex-direction: column;
    justify-content: center;    
}


Navigate to the relevant page on your portal and check that the background and font colors are working as expected.

Regards,
Dharmendra Chavda

Comments

Popular posts from this blog

Data Upload into CRM from Excel Using Power Automate

Run a Dynamics 365 Plugin from JavaScript on Button Click

Update a Lookup Field value using PowerAutomate