Pagination and Sorting

Pagination

The results returned by a Sift search can be paginated by including the data-sift-results-per-page attribute on the Sift outer <div>. This attribute specifies how many results should appear on each page. By default, the first page of the results will be displayed.

@inherits Umbraco.Web.Mvc.UmbracoViewPage

<h1>Paginated Filter</h1>

<div class="sift"
     data-sift-result-document-type="cinemaCento"
     data-sift-results-per-page="7"
     data-sift-result-sort-by="nodeName asc">

    <form class="sift-criteria">

        @Html.AntiForgeryToken()

        <label for="filmName">Name</label>
        <input type="text" id="filmName" name="filmName"
               class="sift-criterion sift-wildcard"
               data-sift-match-property="nodeName" />
        <p></p>

        <input type="submit" value="Search" />

    </form>

    <div class="sift-result">
    </div>

</div>

<script src="~/Scripts/sift.js" type="text/javascript"></script>

The default results partial view includes some pagination links to demonstrate how to switch to the other pages. These are defined in the _SiftDefaultPagination partial view. Take a look at the Search Triggers guide to see how to add these search links.

Sorting

The above example also demonstrates how to sort the results returned from Sift. This is done by adding a data-sift-result-sort-by attribute to the Sift outer <div>. This should be set to a comma-separated list of property names (or nodeName), each followed by either asc or desc.

For a text property to be included in the sort it needs to be flagged as sortable. This is done by including the property name in the Sift.SortableTextFields app setting in Web.config. This does not need to be done for date or numeric fields.

<appSettings>
	...
	<add key="Sift.SortableTextFields" value="nodeName,title" />  
	...
</appSettings>

If content already exists for these properties then you will need to rebuild the Examine index in the Umbraco back office before they can be used.

<< Back to User Guide