Skip to content

ListView

The ListView component provides a flexible way to display hierarchical data in various view modes, including list, table, content, tiles, and icons views. It supports features like selection, grouping, and node manipulation.

This component requires:

  • Metro UI core
  • LESS variables and mixins
<ul data-role="listview">
<li data-caption="Documents">
<ul>
<li data-caption="Report.docx" data-icon="..."></li>
<li data-caption="Presentation.pptx" data-icon="..."></li>
</ul>
</li>
<li data-caption="Images">
<ul>
<li data-caption="Photo1.jpg" data-icon="..."></li>
<li data-caption="Photo2.jpg" data-icon="..."></li>
</ul>
</li>
</ul>
<!-- Selectable ListView -->
<ul data-role="listview" data-selectable="true">
<li data-caption="Documents">
<ul>
<li data-caption="Report.docx"></li>
<li data-caption="Presentation.pptx"></li>
</ul>
</li>
</ul>
<!-- ListView with Custom Icons -->
<ul data-role="listview">
<li data-caption="Documents" data-icon="<svg>...</svg>">
<ul>
<li data-caption="Report.docx" data-icon="<svg>...</svg>"></li>
<li data-caption="Presentation.pptx" data-icon="<svg>...</svg>"></li>
</ul>
</li>
</ul>
<!-- ListView with Description and Date -->
<ul data-role="listview" data-view="table">
<li data-caption="Documents">
<ul>
<li data-caption="Report.docx" data-desc="Word document" data-date="2023-05-15"></li>
<li data-caption="Presentation.pptx" data-desc="PowerPoint presentation" data-date="2023-05-16"></li>
</ul>
</li>
</ul>
ParameterTypeDefaultDescription
listviewDeferrednumber0Deferred initialization time in milliseconds
selectablebooleanfalseIf true, enables item selection with checkboxes
durationnumber100Animation duration for expanding/collapsing nodes in milliseconds
viewstringMetro.listView.LISTView mode (LIST, TABLE, CONTENT, TILES, ICONS, ICONS_MEDIUM, ICONS_LARGE)
selectCurrentbooleantrueIf true, selects the current node when clicked
defaultIconstringfile_iconDefault icon for nodes
onNodeInsertfunctionMetro.noopTriggered when a node is inserted
onNodeDeletefunctionMetro.noopTriggered when a node is deleted
onNodeCleanfunctionMetro.noopTriggered when a node is cleaned
onCollapseNodefunctionMetro.noopTriggered when a node is collapsed
onExpandNodefunctionMetro.noopTriggered when a node is expanded
onGroupNodeClickfunctionMetro.noopTriggered when a group node is clicked
onNodeClickfunctionMetro.noopTriggered when a node is clicked
onNodeDblclickfunctionMetro.noopTriggered when a node is double-clicked
onListViewCreatefunctionMetro.noopTriggered when the listview is created

Gets or sets the view mode.

var listview = Metro.getPlugin('#my-listview', 'listview');
// Get current view
var currentView = listview.view();
// Set view to icons
listview.view(Metro.listView.ICONS);

Toggles a node’s expanded state.

var listview = Metro.getPlugin('#my-listview', 'listview');
listview.toggleNode(document.querySelector('.node-group'));

Toggles selectable mode.

var listview = Metro.getPlugin('#my-listview', 'listview');
listview.toggleSelectable();

Adds a new node. If node is provided, adds as a child of that node.

var listview = Metro.getPlugin('#my-listview', 'listview');
listview.add({
caption: "New Item",
icon: "<svg>...</svg>",
desc: "Description",
date: "2023-05-15"
});

Adds a new group node.

var listview = Metro.getPlugin('#my-listview', 'listview');
listview.addGroup({
caption: "New Group"
});

Inserts a node before another node.

var listview = Metro.getPlugin('#my-listview', 'listview');
var targetNode = document.querySelector('#target-node');
listview.insertBefore({
caption: "New Item"
}, targetNode);

Inserts a node after another node.

var listview = Metro.getPlugin('#my-listview', 'listview');
var targetNode = document.querySelector('#target-node');
listview.insertAfter({
caption: "New Item"
}, targetNode);

Deletes a node.

var listview = Metro.getPlugin('#my-listview', 'listview');
var nodeToDelete = document.querySelector('#node-to-delete');
listview.del(nodeToDelete);

Cleans a node (removes children).

var listview = Metro.getPlugin('#my-listview', 'listview');
var nodeToClean = document.querySelector('#node-to-clean');
listview.clean(nodeToClean);

Gets selected nodes.

var listview = Metro.getPlugin('#my-listview', 'listview');
var selectedNodes = listview.getSelected();

Clears all selections.

var listview = Metro.getPlugin('#my-listview', 'listview');
listview.clearSelected();

Selects or deselects all nodes.

var listview = Metro.getPlugin('#my-listview', 'listview');
// Select all
listview.selectAll(true);
// Deselect all
listview.selectAll(false);

selectByAttribute(attributeName, attributeValue, select)

Section titled “selectByAttribute(attributeName, attributeValue, select)”

Selects nodes by attribute.

var listview = Metro.getPlugin('#my-listview', 'listview');
listview.selectByAttribute('data-type', 'document', true);

Destroys the component.

var listview = Metro.getPlugin('#my-listview', 'listview');
listview.destroy();
EventDescription
onNodeInsertTriggered when a node is inserted
onNodeDeleteTriggered when a node is deleted
onNodeCleanTriggered when a node is cleaned
onCollapseNodeTriggered when a node is collapsed
onExpandNodeTriggered when a node is expanded
onGroupNodeClickTriggered when a group node is clicked
onNodeClickTriggered when a node is clicked
onNodeDblclickTriggered when a node is double-clicked
onListViewCreateTriggered when the listview is created

The ListView component can be styled using the following CSS variables:

VariableDefault (Light)Dark ModeDescription
--listview-item-border-radius4px4pxBorder radius of list items
--listview-item-width220px220pxWidth of list items
--listview-background#ffffff#1e1f22Background color of the listview
--listview-color#191919#dbdfe7Text color of the listview
--listview-color-secondary#919191#bcbcbcSecondary text color
--listview-item-background-hover#d4e2ff#2d2d32Background color on hover
--listview-item-background-active#d4e2ff#28282cBackground color when active
--listview-badge-backgroundtransparenttransparentBackground color for badges
--listview-badge-color#191919#dbdfe7Text color for badges
/* Custom styling for a specific listview */
#my-custom-listview {
--listview-background: #f0f7ff;
--listview-color: #0d47a1;
--listview-item-background-hover: #e3f2fd;
--listview-item-background-active: #bbdefb;
--listview-item-border-radius: 8px;
}

The ListView component supports several view modes that can be set using the data-view attribute:

<ul data-role="listview" data-view="list">
<!-- items -->
</ul>
<ul data-role="listview" data-view="table">
<!-- items -->
</ul>
<ul data-role="listview" data-view="content">
<!-- items -->
</ul>
<ul data-role="listview" data-view="tiles">
<!-- items -->
</ul>
<ul data-role="listview" data-view="icons">
<!-- items -->
</ul>
<ul data-role="listview" data-view="icons-medium">
<!-- items -->
</ul>
<ul data-role="listview" data-view="icons-large">
<!-- items -->
</ul>
  • .listview - Base class for the component
  • .node - Regular node
  • .node-group - Group node
  • .icon - Icon container
  • .caption - Caption text
  • .desc - Description text
  • .date - Date text
  • .content - Content container
  • .current-select - Selected node
  • .expanded - Expanded group node
  • .node-toggle - Toggle button for group nodes
  • .view-list - List view
  • .view-table - Table view
  • .view-content - Content view
  • .view-tiles - Tiles view
  • .view-icons - Icons view
  • .view-icons-medium - Medium icons view
  • .view-icons-large - Large icons view