Wednesday 12 November 2014

SharePoint Content Search Web Part (CSWP)


Content Search Web Part (CSWP):  This is new web part in SharePoint 2013 and SPO. It will take a query and get the results based on query.
We can create a result source (Result source: where we can write query) and select that in CSWP.

We can apply custom Item and Control template to render the data.

Normally all search output pages will expect some input, but in CSWP we can get the result with out input. Mean if you want to show List Items in a page, we can use CSWP with query as select My list items.
So CSWP will get all list items, with out writing any code..we can all filtering for query.

We can use custom display templates (Item/ control template) to show custom rendering.

How to add a Content Search Web Part to a page:

Go to SharePoint site, open any page. Click Edit page.
In the Web Part Zone where you want to add the Web Part, click Add a Web Part.
In the Categories list, click Content Rollup.
In the Parts list, click Content Search, and then click Add.
The CSWP contains a default query, so it already displays some content.
Note: To get our content, we'll need to configure the query in the Web Part.

How to configure a query in a Content Search Web Part on a category page

In the Web Part, click the Web Part Menu , and then click Edit Web Part.
In the Web Part tool pane, click Change query. This will open a dialog box.
Now you can play and try with different query to get your data.

If you want to change the display templates.
Under "Display Templates"
Change "Control" and "Item" dropdowns..You will see some out of box templates...
You can add custom templates also..