0.2.0 • Published 6 years ago

vsdropdown v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

vsdropdown v. 0.1.1

Virtual scroll dropdown - AngularJS reusable UI component

Description

AngularJS directive which implements the virtual scroll dropdown.

1. virtualization

  • only visible items are rendered in the browser
  • good performance even millions of items

2. custom scrollbar

  • scrollbar can be customized by CSS
  • looks similar in all browsers

3. filtering

  • built in global filter
  • uses AngularJS filter

4. responsive UI

  • vsdropdown UI is responsive and scalable to different size of devices

5. tooltips

  • tooltips are used to shown the string which are not fit to the vsdropdown

6. touch and keyboard

  • works with touch devices
  • works with keyboard

7. accepts objects

  • input object is array of objects (items) or array of strings

8. no dependencies

  • Depends only AngularJS

Usage

  • include the vsdropdown-0.1.1.min.js and the vsdropdown-0.1.1.min.css files into your project. See the Build project and the Installation chapters below.
<script src="vsdropdown-0.1.1.min.js"></script>
<link href="vsdropdown-0.1.1.min.css" rel="stylesheet" type="text/css">
  • inject the vsdropdown module into your application module.
angular.module('sampleapp', ['vsdropdown']);
  • add vsdropdown HTML tag into your HTML file. See the HTML example chapter below.
  • add needed Javascript code. See the Javascript example chapter below.

HTML example

<div ng-app="sampleapp" ng-controller="sampleappctrl">
    <vsdropdown options="opt"</vsdropdown>
</div>

Tags

TagDescriptionMandatory
vsdropdownvsdropdown tagyes

Attributes

AttributeDescriptionMandatory
optionsvsdropdown configuration object. See below.yes

Options data (an options attribute in the vsdropdown directive)

AttributeDescriptionValuesMandatory
itemsArray of data shown in the vsdropdown.Array of strings or array of objects.yes
selectedItemsSelected items. Contains all items.Array of strings or array of objectsyes
inputObject which contain sub properties.See below.yes
input.isObjectIs items (see above) array of strings or array of objects.true or falseyes
input.visiblePropNameThis is visible property name. Only if isObject is true.stringdepends value of previous property
input.calculateDisplayValueA callback function which takes the current item and returns a string representation. Only if isObject is true.stringdepends value of previous property
input.propertiesObject which contain sub properties.See below.yes
input.properties.enabledIs properties enabled or not.true or falseif input.isObject is true
input.properties.propsString array of property names of the one item. These properties are visible in properties popover.arrayif input.properties.enabled is true
input.properties.propertyTitleProperty title in the popover.stringif input.isObject is true
input.properties.valueTitleValue title in the popover.stringif input.isObject is true
filterObject which contain sub properties.See below.yes
filter.enabledIs filtering enabled or not. If false the filter input box is hidden.true or falseyes
filter.filterPlaceholderTxtFilter input box placeholder text.stringyes
filter.noHitsTxtFilter no hits text.stringyes
selectionObject which contain sub properties.See below.yes
selection.maximumMaximum selection count. If the dropdown is single select, put number 1 to this.numberyes
selection.selectionsTxtSelections text. Visible in the overlaytextif previous value is bigger than 1
selection.showCountIs selection count visible or not. Count is visible in the show overlay button.true or falseif previous value is bigger than 1
visibleItemCountVisible item count in the selector.numberyes
showTooltipIs tooltips shown or not.true or falseyes
fadeInEffectsIs fade in effects used in the overlay and the tooltips.true or falseyes
itemSelectCbItem select callback function.functionno. It is also possible to use AngularJS watch. See chapter Javascript example

Javascript example

var sampleapp = angular.module('sampleapp', ['vsdropdown']);
sampleapp.controller('sampleappctrl', function ($scope) {

    // Watch the user selections - invoked when the user select/deselect item from the vsdropdown
    $scope.$watch('opt.selectedItems', function (newVal, oldVal) {
        if (newVal !== oldVal) {
            console.log('PARENT - watch: ', newVal);
        }
    }, true);
    
    // Configuration example of the vsdropdown. 
    $scope.opt = {
        items: items,
        selectedItems: selectedItems,
        input: {
            isObject: true,
            calculateDisplayValue: function(item){
                return item.name;
            },
            visiblePropName: 'name',
            properties: {
                enabled: true,
                props: ['id', 'name', 'active'],
                propertyTitle: 'Property',
                valueTitle: 'Value'
            }
        },
        filter: {
            enabled: true,
            filterPlaceholderTxt: 'Type filter...',
            noHitsTxt: 'No hit(s)'
        },
        selection: {
            maximum: 20,
            selectionsTxt: 'selections',
            showCount: true
        },
        visibleItemCount: 4,
        showTooltip: true,
        fadeInEffects: true,
        itemSelectCb: onSelectItem
    };
};

itemSelectCb

Example of the function. See description of the parameters below the example.

function onSelectItem(items, selection, operation) {
    if (selection !== undefined) {
        console.log('PARENT - onSelectItem(): Selected item(s): ', items, ' - Selection: ', selection, ' - Operation: ', operation);
    }
}
FunctionParametersDescription
onSelectItemitems, selection and operationCalled when the user selects/deselects item from the UI.
Parameters
  • items - all selected items
  • selection - item which selection/deselection caused this event
  • operation - select or deselect. select is + and deselect is -

Demo

In the examples folder of this project has the sample application and the online demo is here

Dependencies

Depends on AngularJS. Implemented using the AngularJS version 1.4.3.

Build project

  • Build can be done by executing the grunt command. It creates the dist/debug and the dist/min folders and put files to these folders.
grunt

Installation

  • Installation can be done using the bower. It installs files from the dist/debug and the dist/min folders. Needed CSS and javascript files are located in these folders.
bower install vsdropdown

Compatibility (tested with)

  • IE 9+
  • Firefox 36
  • Google Chrome 41
  • Opera 28.0
  • Mobile Safari 8

License

  • License: MIT

Author

  • Author: kekeh