# j-ServerListing

> j-ServerListing: easy usage; second model $ contains info about data-source { index: Number, page: Number, pages: Number, count: Number, value: YOURDATA }

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 4208c1a50f7cc75a1ba796827c4e8997c324cc25ee989fdabe75822aa0a775d1
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

__Configuration__:

- `paginate {String}` link to a function `function(page)` for pagination
- `pages {Number}` max. pages in pagination (default: `3` --> half + current page + half)
- `scrolltop {Boolean}` scrolls top automatically when the user changes a page
- `parent {String}` jQuery selector for obtaining of height, enables fixed area with custom scrollbars
- `margin {Number}` a margin for `parent` (default: `0`)
- `marginxs {Number}` optional, a top/bottom margin together for `xs` screen width
- `marginsm` a top/bottom margin together for `sm` screen width
- `marginmd` a top/bottom margin together for `md` screen width
- `marginlg` a top/bottom margin together for `lg` screen width
- `pluralizeitems` a pluralization for count of all items, form: `# zero,# one,# two-four,# five and more` (if empty, counter will be hidden)
- `pluralizepages` a pluralization for count of all items, form: `# zero,# one,# two-four,# five and more` (if empty, counter will be hidden)
- `modulo {Number}` can append empty items with `{ EMPTY: 1 }` object (default: `0`)
- `nopages {Boolean}` can hide pagination if the pages are less than `2` (default: `false`)

__Model__:

The model must be in the format below:

```javascript
{
	page: Number,
	count: Number,
	pages: Number,
	items: [{...}, {...}]
}
```

__Tangular layout__:

- `body` {String} contains all rendered items, output is __HTML__
- `page` {Number} current page number
- `pages` {Number} count of pages
- `count` {Number} count of items

__Tangular item__:

- `model` contains an object from `Array`
- second model `$` contains info about data-source `{ index: Number, page: Number, pages: Number, count: Number, value: YOUR_DATA }`

Use it with `<ui-component name="serverlisting">`. 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.

```html example.html
<div class="row">
	<div class="col-sm-6">
		<h2>With layout</h2>
		<ui-component name="serverlisting" path="model" config="paginate:gotopage">
			<script type="text/html">
				<div class="col-xs-4">
					<div>Item: {{ name }}</div>
				</div>
			</script>
			<script type="text/html">
				<div><b>Layout:</b></div>
				<br />
				<div class="row">{{ body | raw }}</div>
			</script>
		</ui-component>
		<br />
	</div>

	<div class="col-sm-6">
		<h2>Without layout</h2>
		<ui-component name="serverlisting" path="model" config="paginate:gotopage">
			<script type="text/html">
				<div>
					<div>Item: {{ name }}</div>
				</div>
			</script>
		</ui-component>
		<br />
	</div>
</div>

<script>

	var model = {};
	model.page = 1;
	model.pages = 3;
	model.count = 10;
	model.items = [];

	for (var i = 0; i < 10; i++)
		model.items.push({ name: GUID(10) });

	function gotopage(page) {
		alert('GO TO PAGE:' + page);
	}

</script>
```
