NexaDom
Pendahuluan
NexaDom adalah library JavaScript yang kuat untuk menangani rendering
data dinamis, pemfilteran, dan paginasi dalam aplikasi web. Library ini
menyediakan cara yang efisien untuk mengelola dan menampilkan dataset
besar dengan fitur seperti virtual scrolling, lazy loading, dan data
chunking.
Instalasi
import NexaDom from './NexaDom.js';
Penggunaan Dasar
const options = {
elementById: 'myList',
search: 'searchInput',
pagination: 'paginationContainer',
order: 10
};
const nexaDom = new NexaDom(options);
Opsi Konfigurasi
Opsi |
Type |
Nilai Default |
Deskripsi |
elementById |
String |
Wajib |
ID dari elemen container |
search |
String |
null |
ID of search input element |
pagination |
String |
null |
ID of pagination container |
order |
Number |
10 |
Items per page |
sortBy |
String |
null |
Field to sort by |
sortOrder |
String |
'ASC' |
Sort order ('ASC' or 'DESC') |
Metode
setData(newData)
Mengatur data baru untuk instance
nexaDom.setData([
{ id: 1, name: "Item 1" },
{ id: 2, name: "Item 2" }
]);
getData(id)
Gets data by ID
const item = nexaDom.getData(1);
filterKey(key, value)
Filters data by key and value
nexaDom.filterKey('category', 'books');
sort(order, sortBy)
Sorts data by specified field
nexaDom.sort('ASC', 'name');
addData(newData, resetPage)
Adds new data to existing dataset
nexaDom.addData(newItems, true);
destroy()
Cleans up and removes instance
nexaDom.destroy();
Filter
NexaDom supports template filters using the pipe syntax:
{set.property|filter1|filter2}
Built-in Filters
- date - Formats dates
- currency - Formats numbers as currency
- uppercase - Converts text to uppercase
- lowercase - Converts text to lowercase
Penanganan Data
Virtual Scrolling
For large datasets, NexaDom automatically implements virtual scrolling
to improve performance.
Lazy Loading
Images and heavy content are loaded only when they enter the viewport.
Data Chunking
Large datasets are automatically split into manageable chunks for better
performance.
Event
Event Name |
Description |
dataReloaded |
Fired when data is successfully reloaded |
dataReloadError |
Fired when data reload fails |
Event Handling Example
document.addEventListener('dataReloaded', (event) => {
console.log('Data reloaded:', event.detail);
});
Contoh
Basic List with Pagination
<div id="myList">
<script type="text/template" data-template="list">
<div class="item">
<h3>{set.title}</h3>
<p>{set.description}</p>
</div>
</script>
</div>
<div id="pagination"></div>
<script>
const nexaDom = new NexaDom({
elementById: 'myList',
pagination: 'pagination',
order: 10
});
nexaDom.setData([
{ title: 'Item 1', description: 'Description 1' },
{ title: 'Item 2', description: 'Description 2' }
]);
</script>
Searchable List with Filters
<input type="text" id="search" placeholder="Search...">
<select id="categoryFilter">
<option value="all">All Categories</option>
<option value="books">Books</option>
<option value="electronics">Electronics</option>
</select>
<div id="productList">
<script type="text/template" data-template="list">
<div class="product">
<h3>{set.name}</h3>
<p>Category: {set.category}</p>
</div>
</script>
</div>
<script>
const nexaDom = new NexaDom({
elementById: 'productList',
search: 'search',
filter: 'categoryFilter',
filterBy: 'category',
searchableFields: ['name', 'category']
});
</script>
Catatan Penting
-
Selalu panggil destroy() saat menghapus instance NexaDom untuk
mencegah kebocoran memori
-
Dataset besar (>1000 item) secara otomatis menggunakan virtual
scrolling
- Sintaks template bersifat case-sensitive
- Filter kustom dapat ditambahkan melalui kelas NexaFilter