Freigeben über


How do we apply a custom filter on Project Center webpart Dynamically(usefull when added on a custom site....)

Welcome to First post ........

We can do a filtering(custom filter) on Project Center Dynamically. For instance Projet Center webpart is added on a Sitecolltion and while opening the site collection project Center should do a filtering based on a specific criteria

1. Sample code for extending Project Center is Available with SDK (CustomizeProjectCenter)

2. We have to attach a fuction to any of the event were we need to do the filtering on Project Center ( on the below sample code i have used onCellfocusChanged Event)

_grid.AttachEvent(SP.JsGrid.EventType.on, Cffilter);

 

3. Write a fuction for the filtering

function Cffilter(eventArgs) {
            
            var a = {}           
            var sites = window.location.href;                  
            var len = n.lastIndexOf("/");
            var myString = n.substring(0, len+1);
            var stname = n.replace(myString, "");

            a.ClientFilterXml = '<Filter><FieldComparison><Field>7806971e-9291-49ea-ba75-dd726faffba6</Field><Operator>Equals</Operator><Operand>' + stname + '</Operand></FieldComparison></Filter>'
            a.ServerFilterXml='<Filter xmlns:pwa=\"https://microsoft.com/ProjectServer/FilterSchema.xsd\"><Criteria><LogicalOperator logicalOperationType=\"Nop\"><FieldOperator fieldOperationType=\"Equal\"><CustomField fieldName=\"27955ccb-860b-45ec-8722-dfb02e6a2dca\" customFieldType=\"CodeValue\" ISMULTIVALUE=\"0\"/><Operand LTUID=\"89417fcc-768c-47aa-aa4b-d71bd979825e\">8f8ecc68-ed8a-4bfa-89d8-424db1353a64</Operand></FieldOperator></LogicalOperator></Criteria></Filter>'
            projectCenterComponent.get_GridSatellite().HandleFilter(a)
}

Scenario : in This sample we are doing the filtering based on the site colleciton name and a custom field which is created in Project Server

This Project Level custom field should be present in the view

ServerFilterXml doenst have any effect on this, however a should have a dummy ServerFilterXml

ClientFilterXml parameter plays the role here

Parameters:

stname is the valiable based on which the filtering will be done

7806971e-9291-49ea-ba75-dd726faffba6 is the UID for Project Level Custom field.

4. Once you actiavate the feature on the site , above code will do the filtering...

Happy coding ......�  Cheers .. Ajith ....