IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
The sfCollection directive enables you to display a collection of items and provides you with the functionality to select single or multiple of those items.
sfCollection
The following tutorial demonstrates how to add a generic collection directive in a widget designer's view. Keep in mind that you are free to use selectors and directives outside of widget designers.
To add the generic collection directive:
Sitefinity CMS automatically registers the scripts you need and, if no other designer view with explicitly set priority exists, Sitefinity CMS sets your designer view priority 1. In case you need to have full control over the scripts that are loaded or you want to set custom priority, you can alternatively create your own DesignerView.YourView.json file. If you have a JSON file that matches the convention (even if empty), this automatic scripts registration will not occur. In your DesignerView.<YourView>.json file, add a scripts array. As a result, the file content looks similar to the following:
DesignerView.YourView.json
JSON
DesignerView.<YourView>.json
scripts
In your file, right before the definition of your custom view controller, place the following code:
angular.module('designer').requires.push('sfCollection');
Your designer controller exposes the following scope items, so that it binds them to the sfCollection directive.
In your DesignerView.<YourView>.cshtml file, place the following tag where you want to render the sfCollection directive:
DesignerView.<YourView>.cshtml
The sf-collection tag exposes the following attributes:
sf-collection
sf-data
sf-model
sf-multiselect
sf-identifier
sf-deselectable
true
sf-template-url
SfCollectionTemplate.html
sf-template-url="SfCollectionTemplate.html"
To provide notification when item is selected, the sfCollection directive emits a custom selection event. To subscribe to the selection event, use the following code in your designer's controller:
$scope.$on('sf-collection-item-selected', function (event, item) { });
In the markup of your custom sfCollection template, add the following code snippet:
The sfCollection directive’s scope provides 2 additional methods for switching between the Grid and List modes:
switchToGrid()
switchToList()
To use these 2 methods, you must provide 2 CSS files in the custom sfCollection template:
sf-collection-grid
sf-collection-list
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important