It's similar component like j-Suggestion
, but has improved design and supports more handy features.
- singleton
- works with touches
- supports dark mode
IMPORTANT: by default this component renders a value as a text from
name
property.
- jComponent
v19|v20
Methods:
Method: component.show(options)
options.element {Element/jQuery Element}
options.items {Array/String/Function}
a list of items (String
type means a link to data-source)options.offsetX {Number}
optional,x
offset (default:0
)options.offsetY {Number}
optional,y
offset (default:0
)options.offsetWidth {Number}
optional,width
offset (default:0
)options.placeholder {String}
optional, a placeholder for search field- NEW
options.height {Number}
optional, a height of the container (default:180
) options.render {Function}
optional, a function for customized render of itemfunction(item, text)
must returnHTML
options.custom {Boolean/String}
optional, enables returning a value not defined inoptions.items
, default:false
options.minwidth {Number}
optional, a minimal width, default200
options.maxwidth {Number}
optional, a maximal width, defaultinfinite
options.callback(selected_item, element, iscustom, e) {Function}
is triggered when the user clicks on the itemoptions.key {String}
optional, a defaultkey
fortext
value (default:name
)options.empty {String}
optional, adds empty fieldoptions.exclude {Function}
optional, can exclude items and must return a booleanfunction(item) { return item.id !== 100 }
options.close {Function}
optional, can determine closing of paneloptions.search {Boolean/String}
optional, can hide search field (default:true
) or{String}
(key name) can map a value for searchingoptions.selected {Object}
optional, can contain a selected value (default:undefined
)options.align {String}
optional,left
(default),right
orcenter
options.position {String}
optional,top
(default),bottom
options.raw {Boolean}
optional, this option disables escaping of characters (in other words: HTML content will be allowed in labels of items, default:false
)options.classname {String}
optional, a custom container class for all items- absolute positioning works only if
options.element
is not definedoptions.x {Number}
absolute position Xoptions.y {Number}
absolute position y
options.checkbox {Boolean}
optional, enables checkboxesoptions.checked {Array String}
optional, identifiers of checked items- targeted for
options.items {Function(q, next)}
- the callback returns only raw identifiers
Array {String}
- targeted for
- NEW
options.template {String}
optional, a custom Tangular template e.g.{{ name }}
(default: null)
Method: component.hide()
Configuration:
placeholder
- a placeholder for the search inputcreate
- a placeholder forCreate
label (default:Create
)
Supported item fields:
name {String}
a label nametemplate {String}
optional, a custom Tangular templateclassname {String}
optional, adds additional classes into the<li>
elementdisabled {Boolean}
optional, it can disable itemselected {Boolean}
optional, it selects item
Formatting via Tangular:
var opt = {};
opt.items = [];
opt.push({ name: 'Total.js', template: '<b>{{ name }}</b>' });
Formatting via custom function:
var opt = {};
opt.items = [];
opt.push({ name: 'Total.js' });
opt.push({ name: 'Express.js' });
opt.push({ name: 'Koa.js' });
opt.render = function(item, name) {
return '<b>' + name + '</b>';
};
Adding of custom class:
var opt = {};
opt.items = [];
opt.push({ name: 'Total.js', classname: 'your_class_name' });
Server-side searching:
var opt = {};
opt.element = your_element;
opt.items = function(search, next) {
next([{ name: 'Item 1' }, { name: 'Item 2' }]);
};
opt.callback = function(selected) {
console.log(selected);
};
SETTER('directory/show', opt);
Good to know:
- if
checkboxes:true
then the component extend items by adding a timestampselectedts {Number}
due to order
- Peter Širka [email protected]
- License