ForgeComponents
en

Components

j-SearchData

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20

This component tries to filter data according to the search phrase.


Configuration:

  • datasource {String} required - a path to the data-source with list of items Array
  • output {String} required - a path for filtered items
  • key {String} required - a key/property name for searching (default: name)
  • delay {Number} a delay (default: 50 ms)
  • splitwords {Boolean} tries to find word in various position (default: true)

Good to know:

This component adds classes below automatically when:

  • class ui-search-used is added when the user searches for something
  • class ui-search-empty is added when the user searches for something and at the same time nothing was found

Use it with <ui-component name="searchdata">. When the component is not loaded yet, jComponent downloads it on first use from the address in DEF.fallback (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

example.html
<ui-component name="textbox" path="search" config="type:search"></ui-component>
<br />
<ui-component name="searchdata" path="search" config="datasource:searchitems;output:searchoutput">
	<ui-bind path="searchoutput" config="template" class="block">
		<script type="text/html">
			{{ foreach m in value }}
				<div>{{ m.name }}</div>
			{{ end }}
		</script>
	</ui-bind>
</ui-component>

<script>

	// Search phrase
	var search = '';

	// Datasource for filtering
	var searchitems = [{ name: 'Apples' }, { name: 'Oranges' }, { name: 'Pears' }, { name: 'Black-eye bean' }, { name: 'Broccoli' }];

	// Here will be stored all filtered items
	var searchoutput = [];

</script>