ColumnBar
The ColumnBar component is used to show and configure the columns of a datatable.
import { ColumnBar } from "@schukai/monster/source/components/datatable/columnbar.mjs";Introduction
The Monster Datatable web component is a powerful and flexible tool for displaying data in a tabular format. It is designed to be user-friendly and highly customizable, making it suitable for a wide range of applications.
Key Features
- Dynamic Interaction: Allows users to interact with content dynamically, making the web experience more intuitive and user-focused.
- Customizable Appearance: Enables customization of the table’s appearance to align with the visual style of your brand or application, ensuring a consistent look and feel.
- Accessibility: Built with accessibility in mind, ensuring a seamless experience for all users.
- Programmatic Control: Offers methods like
click,focus, andblurto programmatically control the table’s behavior, giving developers enhanced flexibility.
Enhancing the User Experience
The Monster Datatable enhances user experience by providing a more intuitive and interactive way to display data. It allows users to interact dynamically with content, making the web experience more engaging and user-centered.
Getting Started
Let's begin with a simple example to demonstrate the functionality of the Monster Datatable.
A Basic Example
First, add the Monster Datatable element to your HTML document:
<monster-datatable></monster-datatable>
Now, define the template for each column by using the <template> element within the Monster Datatable element. Each <div> within the template represents a column.
<monster-datatable>
<template id="row">
<div data-monster-head="id" data-monster-replace="path:row.id"></div>
<div data-monster-head="name" data-monster-replace="path:row.name"></div>
</template>
</monster-datatable>
In this setup, the <div> elements in the template have the data-monster-head attribute, which specifies the column header. The data-monster-replace attribute defines the column value, with values sourced from the row object passed to the template.
You can also configure the key for the row object using the templateMapping.row-key option. If not configured, the default key row is used.
Next, you can add data to the table using JavaScript. The simplest way to do this is by setting data through the setOption method:
const datatable = document.querySelector('monster-datatable');
datatable.setOption('data', [
{ "id": "1", "name": "John Doe" },
{ "id": "2", "name": "John Smith" },
{ "id": "3", "name": "Max Mustermann" }
]);
Using a Data Source
Alternatively, you can use a data source to populate the table with data.
<monster-datasource-dom></monster-datasource-dom>
Add the data to be displayed in the table within this data source element. The data source element must have a unique selector, allowing the Monster Datatable element to identify which data source to use. In the simplest case, you can assign an ID to the element, which acts as a selector.
By default, the DataTable looks for the key "dataset" in the data source as the data provider for the table, but this can be configured using the mapping.data option.
<monster-datasource-dom id="myDataSourceID">
<script type="application/json">
{
"dataset": [
{ "id": 1, "name": "John Doe" },
{ "id": 2, "name": "Jane Doe" },
{ "id": 3, "name": "Max Mustermann" }
]
}
</script>
</monster-datasource-dom>
Now, specify the data source for the Monster Datatable by using the data-monster-datasource-selector attribute.
<monster-datatable data-monster-datasource-selector="#myDataSourceID"></monster-datatable>
As with the basic example, the table is now fully functional. Data is loaded from the data source into the table. For more complex cases, such as data from a REST API, additional configuration options are available.
Further examples can be found in the Usage tab.
Empty
This is a simple and empty datatable. It is a powerful and flexible tool for displaying data in a tabular format. The Monster Datatable is designed to be straightforward to use and highly customizable, making it suitable for a wide range of applications.
Javascript
import "@schukai/monster/source/components/datatable/datatable.mjs";HTML
<monster-datatable>
</monster-datatable>Stylesheet
/** no additional stylesheet is defined **/Component Design
This component is built using the Shadow DOM, which allows it to encapsulate its internal structure and styling. By using a shadow root, the component's internal elements are isolated from the rest of the webpage, ensuring that external styles or scripts cannot accidentally modify its internal layout or behavior.
Shadow DOM and Accessibility
Since the component is encapsulated within a shadow root, direct access to its internal elements is restricted. This means that developers cannot manipulate or style these elements from outside the component. The Shadow DOM helps maintain consistency in the design and behavior of the component by preventing external interference.
Customizing Through Exported Parts
While the Shadow DOM restricts direct access to the component's internal structure, customization is still possible through exported parts. Specific parts of the component are made accessible for styling by being explicitly marked for export. These exported parts can be targeted and customized using CSS, allowing you to modify the appearance of the component without compromising its encapsulation.
Available Part Attributes
control: This part represents the entire control area of the slider, including navigation buttons and thumbnails. Use this to style the general layout and background of the control panel.
Below is an example of how to use CSS part attributes to customize different parts of the Control.
monster-button::part(control) {
background-color: #f0f0f0;
padding: 10px;
}
Explanation of the Example
monster-button::part(control): Styles the entire control panel, giving it a light background color and some padding.
Accessibility
Accessibility is a key consideration in the design of this component. By following best practices for web accessibility, the component ensures that users of all abilities can interact with it effectively. This includes support for keyboard navigation, screen readers, and other assistive technologies to provide an inclusive user experience.
HTML Structure
<monster-column-bar></monster-column-bar>JavaScript Initialization
const element = document.createElement('monster-column-bar');
document.body.appendChild(element);Exported
ColumnBarDerived from
CustomElementOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomElement.
- since
- deprecated
Properties and Attributes
The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomElement.
data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.data-monster-option-[name]: Sets the value of the configuration option[name]for the collapse component when used as an HTML attribute.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomElement.
Static methods
[instanceSymbol]()- {symbol}
instanceof operator.getCSSStyleSheet()- {CSSStyleSheet[]}
getTag()- {string}
Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()- {void}
connectedCallback()4.14.0- {void}
disconnectedCallback()4.14.0- {void}
Other methods
customization()Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.