SharePoint : How to filter an external data XsltListViewWebPart in SharePoint Designer ?

sharepoint 2013
sharepoint 2013

Context : You use Business Data Connectivity to retrieve external data in SharePoint, and you wish to display a filtered view of this data in a page.
In SharePoint Designer, you insert a Data View of that external data.
Then, there are 2 ways to filter it :

  • By using the « Filter » button in the office ribbon :
SharePoint Designer Filter
SharePoint Designer Filter

This actually generates a CAML query :
SharePoint_BDC_Filter_External_Data_2

  • By passing a parameter to the finder method of the BDC Model. You can do this manually or by using the « Search » button :

SharePoint_BDC_Filter_External_Data_1b
It generates this code in the View element :
SharePoint_BDC_Filter_External_Data_3
You should use the second solution. Why ? We could consider the CAML query as a « front-end » filter. It means that ALL the records are sent by the BDC, and then the CAML query filter it.
If you retrive thousands of records, it can affect performances.
If you pass a parameter directly to the BDC (finder method), the request sent to the external source will be filtered, and SharePoint will have to deal with less data.
Maybe you will have to create a new finder method in your BDC, but it worth the time spent on it !