Skip to main content

sortable.list.view

SortableListView : d2/sdk/controls/list/sortable.list.view

A flat list view backed by a Backbone.Collection. Items in the list view could be dragged around to re-order them within the list.

Extends: Marionette.CompositeView
Example (Typical usage)

//In mybundle/trial/list/sortable.listitem.hbs
<div class="item-label" data-d2-key="{{name}}">{{label}}</div>

//In a test module
define([
'nuc/lib/backbone',
'nuc/lib/marionette',
'd2/sdk/controls/list/sortable.list.view',
'hbs!mybundle/trial/list/sortable.listitem'
], function(Backbone, Marionette, SortableListView, template){
'use strict';

var ItemView = Marionette.ItemView.extend({
template: template,
templateHelpers: function() {
return {
label: this.model.get('label'),
name: this.model.get('id')
};
}
});

var collection = new Backbone.Collection([
{id: '1', label: 'One'},
{id: '2', label: 'Two'},
{id: '3', label: 'Three'}
]);

var listView = new SortableListView({itemView: ItemView, collection: collection, hasNonRemovableItem: true, isItemNonRemovable: function(){return true;}});
new Marionette.Region({el: '.el-host'}).show(listView);

});

SortableListView~SortableListView

Kind: inner class of SortableListView

new SortableListView(options)

ParamTypeDefaultDescription
optionsobject

Constructor options. Following are the options specifically supported by the list apart from those from its supertype.

options.itemViewMarionette.ItemView

View class to use for rendering each item in the list.

[options.hasNonRemovableItem]Booleanfalse

Whether the list has non-removable item. If set to true then isItemNonRemovable() callback is executed for each item to decide removability.

[options.isItemNonRemovable]RemovableDetectionCallback

Callback to decide if a particular item is non-removable

SortableListView~RemovableDetectionCallback ⇒ Boolean

Kind: inner typedef of SortableListView
Returns: Boolean - Return true to indicate the item shouldn't be removable.

ParamTypeDescription
modelBackbone.Model

Model behind the item being evaluated.