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.
Feather's sfCollection directive enables you to display a collection of items and provides you with the functionality to select single or multiple of those items.
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 Feather selectors and directives outside of widget designers. For more information, see Use content selectors outside of a widget designer's view.
To add the generic collection directive:
Feather automatically registers the scripts you need and, if no other designer view with explicitly set priority exists, Feather 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
{ "priority": 1, "components" : ["sf-collection"] }
In your DesignerView._YourView.js 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.
angular.module('designer') .controller('SimpleCtrl', ['$scope', 'propertyService', 'serverContext', function ($scope, propertyService, serverContext) { $scope.items = [{ Id: '1', Title: "Folder1" }, { Id: '2', Title: "Folder2" }, { Id: '3', Title: "Folder3" }]; }]);
In your DesignerView.YourView.cshtml file, place the following tag where you want to render the sfCollection directive:
<sf-collection sf-data="items" sf-model="[selectedItem]" sf-multiselect="[false/true]" sf-identifier="[Title]" sf-deselectable="[false/true]" sf-template-url="[path to your template]"></sf-collection>
The sf-collection tag exposes the following attributes:
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 desinger's controller:
$scope.$on('sf-collection-item-selected', function (event, item) { });
In the markup of your custom sfCollection template, add the following code snippet:
<div id="grid"> <li ng-repeat="item in items" class="col-md-4" ng-click="select(item)"> {{::item.Title}} </li> </div> <div id="list"> <li ng-repeat="item in items" ng-click="select(item)"> {{::item.Title}} </li> </div> <div> <button ng-click="switchToGrid()">Grid</button> <button ng-click="switchToList()">List</button> </div> <style> .sf-collection-grid > div#list { display: none; } .sf-collection-list > div#grid { display: none; } </style>
The sfCollection directive’s scope provides 2 additional methods for switching between the Grid and List modes:
To use these 2 methods, you must provide 2 CSS files in the custom sfCollection template:
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