Skip to content

Remote Dataset

A powerful component for displaying remote data with built-in pagination, search, sorting, and customizable entry rendering. The Remote Dataset component fetches data from remote APIs and provides a flexible interface for displaying and interacting with the data.

  • Hooks (for debounced search)
  • Pagination component
  • Input component
  • Select component
<div data-role="remote-dataset"
data-url="https://api.example.com/data"
data-key-data="items"
data-on-draw-entry="drawEntry">
</div>

Page-based Pagination (pageMode=“page”)

Section titled “Page-based Pagination (pageMode=“page”)”
<div data-role="remote-table"
data-page-mode="page"
data-offset="1"
data-key-offset="page"
data-key-data="data"
data-key-limit="perPage"
data-key-total="totalProducts"
data-fields="id, title, price"
data-url="https://api.example.com/products">
</div>

Offset-based Pagination (pageMode=“offset” - default)

Section titled “Offset-based Pagination (pageMode=“offset” - default)”
<div data-role="remote-table"
data-page-mode="offset"
data-key-offset="skip"
data-key-limit="limit"
data-key-data="products"
data-key-total="total"
data-fields="id, title, price"
data-url="https://api.example.com/products">
</div>
<div data-role="remote-dataset"
data-caption="Products"
data-url="https://dummyjson.com/products"
data-url-search="https://dummyjson.com/products/search"
data-key-offset="skip"
data-key-limit="limit"
data-key-data="products"
data-key-total="total"
data-key-sort="sortBy"
data-key-order="order"
data-key-search="q"
data-sort="rating:desc"
data-sort-rules="price:asc:Price Asc,price:desc:Price Desc,rating:desc:By rating"
data-rows="10"
data-rows-steps="10,25,50,100"
data-page-mode="offset"
data-on-draw-entry="drawEntry"
data-cls-body="d-flex flex-row flex-wrap gap-1 mt-4"
data-cls-pagination="mt-4 d-flex flex-justify-center">
</div>
<div class="d-flex flex-row gap-2">
<input type="text" id="search" placeholder="Search...">
<select id="sorting"></select>
<select id="rows"></select>
</div>
<div data-role="remote-dataset"
data-url="https://api.example.com/data"
data-search-control="#search"
data-sorting-control="#sorting"
data-rows-count-control="#rows"
data-on-draw-entry="drawEntry">
</div>
const dataset = Metro.makePlugin('#myDataset', 'remote-dataset', {
url: 'https://api.example.com/data',
keyData: 'items',
onDrawEntry: function(entry, index) {
return `<div class="item">${entry.title}</div>`;
}
});
ParameterTypeDefaultDescription
captionstring""Caption text displayed above the dataset
urlstring""Primary URL for fetching data
urlSearchstring""Alternative URL for search requests
methodstring”GET”HTTP method for requests
limitnumber10Number of items per page
offsetnumbernullStarting offset (auto-calculated based on pageMode)
sortstring""Default sort field and order (format: “field:order”)
keyLimitstring""Query parameter name for limit
keyOffsetstring""Query parameter name for offset
keyTotalstring""Response key containing total items count
keyDatastring""Response key containing data array
keySortstring""Query parameter name for sort field
keyOrderstring""Query parameter name for sort order
keySearchstring”q”Query parameter name for search
shortPaginationbooleanfalseUse simple prev/next pagination
rowsnumber10Initial number of rows per page
rowsStepsstring”10,25,50,100”Available rows per page options
sortRulesstring""Available sorting options (format: “field:order:label:icon”)
showServiceBlockbooleantrueShow the service block with controls
quickSearchbooleantrueShow built-in search input
selectOrderbooleantrueShow sorting dropdown
selectCountbooleantrueShow rows count dropdown
showMorebooleantrueShow “Load More” button
showPaginationbooleantrueShow pagination controls
paramsobjectnullAdditional query parameters
searchControlstringnullSelector for external search control
sortingControlstringnullSelector for external sorting control
rowsCountControlstringnullSelector for external rows count control
searchThresholdnumber3Minimum characters to trigger search
sortLabelstring""Label for sorting dropdown
rowsLabelstring""Label for rows count dropdown
searchLabelstring""Label for search input
pageModestring”offset”Pagination mode: “offset” or “page”
clsBodystring""CSS classes for dataset body
clsPaginationstring""CSS classes for pagination
clsSearchBlockstring""CSS classes for search block
clsOrderBlockstring""CSS classes for order block
clsRowsCountBlockstring""CSS classes for rows count block
clsServiceBlockstring""CSS classes for service block
  • addParam(key, value) - Adds a single query parameter to requests.
  • addParams(params) - Adds multiple query parameters to requests.
  • clearParams() - Clears all additional query parameters.
  • load(append) - Manually triggers data loading. Set append to true to append data instead of replacing.
  • destroy() - Destroys the component and removes it from DOM.
const dataset = Metro.getPlugin('#myDataset', 'remote-dataset');
// Add custom parameters
dataset.addParam('category', 'electronics');
dataset.addParams({
minPrice: 100,
maxPrice: 500
});
// Reload data
dataset.load();
// Load more data (append)
dataset.load(true);
// Clear parameters and reload
dataset.clearParams();
dataset.load();
EventDescription
onBeforeLoadFired before data loading. Receives URL and component instance. Should return modified URL.
onLoadFired after data is loaded. Receives response data and component instance. Should return processed data.
onDrawEntryFired for each data entry to render custom HTML. Receives entry data and index. Should return HTML string.
onDatasetCreateFired when the component is created
// Using data attributes
<div data-role="remote-dataset"
data-on-before-load="beforeLoadHandler"
data-on-load="loadHandler"
data-on-draw-entry="drawEntryHandler">
</div>
// JavaScript functions
function beforeLoadHandler(url, component) {
console.log('Loading from:', url);
return url + '&timestamp=' + Date.now();
}
function loadHandler(data, component) {
console.log('Data loaded:', data);
return data; // Return processed data
}
function drawEntryHandler(entry, index) {
return `
<div class="data-entry">
<h3>${entry.title}</h3>
<p>${entry.description}</p>
</div>
`;
}
VariableDefaultDescription
--remote-dataset-gap10pxGap between service block elements
--remote-dataset-order-block-size200pxWidth of the sorting dropdown block
--remote-dataset-count-block-size140pxWidth of the rows count dropdown block
#my-dataset {
--remote-dataset-gap: 20px;
--remote-dataset-order-block-size: 250px;
--remote-dataset-count-block-size: 160px;
}
  • .remote-dataset - Main component container
  • .dataset-caption - Caption text styling
  • .dataset-body - Container for data entries
  • .dataset-load-more - Load more button container
  • .dataset-pagination - Pagination container
  • .service-block - Container for search, sorting, and count controls
  • .search-block - Search input container
  • .order-block - Sorting dropdown container
  • .count-block - Rows count dropdown container
  • .short-pagination - Simple prev/next pagination style
  • .product-card - Example styling for product entries (from examples)
  • The component automatically handles URL construction with query parameters
  • Search functionality includes debouncing to prevent excessive API calls
  • Supports both offset-based and page-based pagination
  • The onDrawEntry callback is required for rendering data entries
  • External controls can be used instead of built-in service block controls
  • The component supports both GET and other HTTP methods for data fetching
  • Always provide the onDrawEntry callback to render your data entries
  • Use appropriate keyData, keyTotal, and other key parameters to match your API response structure
  • Consider using urlSearch for search-specific endpoints that may have different response formats
  • Use external controls when you need more complex UI layouts
  • Implement proper error handling in your onLoad callback
  • Use CSS variables to maintain consistent styling across your application
  • Test pagination with different pageMode settings to match your API expectations