Tuesday, June 7, 2022

D365 Grid/List row color change using method override

 Today, I received the requirement from my functional to change the row color for Purchase Order List Page Grid   on any specific condition... 


As we all knows in custom form its really easy using Displayoption()  to achieve but in my case I need to do this on exists form using method override/Event handler of Data source.. 

There is an event available in data source OnDisplayOptionInitilized. I copied the event handler and paste on my class.



Following are the code 
[FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::DisplayOptionInitialize)]
    public static void PurchTable_OnDisplayOptionInitialize(FormDataSource sender, FormDataSourceEventArgs e)
    {
        PurchTable purchTable; //= sender.cursor(); wrong
        FormDataSourceDisplayOptionInitializeEventArgs eventArgs = e as FormDataSourceDisplayOptionInitializeEventArgs;
        purchTable = eventArgs.record(); //correct

         

        if(today() < purchTable.VendFromDate)
        {
            eventArgs.displayOption().textColor(WinAPI::RGB2int(0, 0, 255));  // Blue
        }
        else if (today() > purchTable.VendToDate)
        {
            eventArgs.displayOption().textColor(WinAPI::RGB2int(255,0,0)); // Red
        }
        else
        {
            eventArgs.displayOption().textColor(WinAPI::RGB2int(76, 187, 23)); // Green
            
        } 
    }

Here is the result







No comments:

Post a Comment