Class

DataComponent

kiss.ui.DataComponent(config) → {HTMLElement}

The DataComponent derives from Component.

This is an abstract class: don't use it directly. It's the base class for all the components used to display a collection of records, like:

  • Datatable
  • Calendar
  • Kanban
  • Timeline
  • ChartView
  • Dashboard

Each DataComponent is associated with its own Collection.

The Collection can be provided directly in the config. If not, a Model must be passed instead, and a new Collection will be created from this Model.

A DataComponent can manipulate its collection:

  • selecting the fields to display
  • filtering the data
  • sorting the data
  • grouping the data

These operations are achieved thanks to built-in windows that you can display using:

// Display the window to select fields
myComponent.showFieldsWindow(x, y, color)

// Display the window to sort data
myComponent.showSortWindow(x, y, color)

// Display the window to filter data
myComponent.showFilterWindow(x, y, color)

A DataComponent can persist its configuration inside its associated record, using updateConfig method.

A DataComponent needs to be setup with either a collection or a model. For this, you can directly pass the collection or the model in the config. Or you can pass a collectionId or a modelId, and the component will retrieve the collection or the model from the ones declared in kiss.app.models and kiss.app.collections.

Constructor

# new DataComponent(config) → {HTMLElement}

Parameters:
Name Type Attributes Description
config object
collection object <optional>

Optional collection.

collectionId string <optional>

Optional collectionId.

model object <optional>

Optional model.

modelId string <optional>

Optional modelId.

record object <optional>

Optional record to persist the view configuration.

View Source client/ui/abstract/dataComponent.js, line 51

HTMLElement

Methods

# async _updateToolbar()

Reload the toolbar, if any In the generic case, the toolbar is a set of buttons that can be hidden or shown according to its settings. For now, we only manage the "create" button.

View Source client/ui/abstract/dataComponent.js, line 797

# async copySelectionToClipboard()

Copy the selection to the clipboard

View Source client/ui/abstract/dataComponent.js, line 1655

# async createRecord(model)

Open the form to create a new record

Important: this method can be overriden in the instanced component

Parameters:
Name Type Description
model object

Model to create the record

View Source client/ui/abstract/dataComponent.js, line 1417

# createSearchFilter(value) → {object}

Create a filter that appends the search term to the existing filters

Parameters:
Name Type Description
value string

View Source client/ui/abstract/dataComponent.js, line 1354

The filter configuration

object

# async export()

Export records as XLS or JSON

View Source client/ui/abstract/dataComponent.js, line 1496

# formatValueForClipboard(column, value) → {*}

Format a value for the clipboard

Parameters:
Name Type Description
column object

Column configuration

value *

Value to format

View Source client/ui/abstract/dataComponent.js, line 1688

The formatted value so it can be used in the clipboard for copy/paste

*

# async ftsearch(value)

Full-text search on all text fields

Parameters:
Name Type Description
value string

View Source client/ui/abstract/dataComponent.js, line 1341

# getColumn(fieldId) → {object}

Get the column config used to display a field

Parameters:
Name Type Description
fieldId string

View Source client/ui/abstract/dataComponent.js, line 1067

The column config

object

# getColumns() → {Array.<object>}

Get the view columns

View Source client/ui/abstract/dataComponent.js, line 944

Array of column definitions

Array.<object>

# getFields() → {Array.<object>}

Get the view fields.

Note: in a some view (like datatables), fields are the same thing as columns.

View Source client/ui/abstract/dataComponent.js, line 955

Array of column definitions

Array.<object>

# getLocalConfig() → {object}

When a view configuration can't be persisted into db, it can be stored and retrieved from the local storage

View Source client/ui/abstract/dataComponent.js, line 713

The view configuration stored locally

object

# getSelectedRecords() → {array}

Get the list of selected records

View Source client/ui/abstract/dataComponent.js, line 1444

Array of records

array

# getSelection() → {Array.<string>}

Get the list of ids of selected records

View Source client/ui/abstract/dataComponent.js, line 1434

The list of selected record ids

Array.<string>

# groupBy(groupFields)

Group by a list of fields

Parameters:
Name Type Description
groupFields Array.<string>

List of field names (not ids)

View Source client/ui/abstract/dataComponent.js, line 442

Example
myDatatable.groupBy(["Country", "City", "Age"])

# hideSearchBar()

Reset the search made from the search bar

View Source client/ui/abstract/dataComponent.js, line 1318

# async reload()

Reload the component's data and re-render it

View Source client/ui/abstract/dataComponent.js, line 659

# async resetLocalViewParameters()

Reset all local component parameters:

  • collection configurations (sort, filter, group)
  • columns configuration (visibility, width, colors, aggregation)

When the component's configuration is persisted into local storage, it's useful to be able to reset it

View Source client/ui/abstract/dataComponent.js, line 772

this

# resetSearchBar()

Reset the search made from the search bar

View Source client/ui/abstract/dataComponent.js, line 1330

# selectRange(rangeStart, rangeEnd)

Select multiple records (using the SHIFT key)

Parameters:
Name Type Description
rangeStart number
rangeEnd number

View Source client/ui/abstract/dataComponent.js, line 1477

# async selectRecord(record)

Show a single record

Important: this method can be overriden in the instanced component

Parameters:
Name Type Description
record object

Record to show

View Source client/ui/abstract/dataComponent.js, line 1405

# async selectRecordById(recordId)

Show a single record (passing its id)

Parameters:
Name Type Description
recordId string

id of the record to show

View Source client/ui/abstract/dataComponent.js, line 1392

# showFieldsWindow(xopt, Yopt, coloropt)

Show a modal window to select / deselect fields

Parameters:
Name Type Attributes Description
x number <optional>

x coordinate

Y number <optional>

y coordinate

color string <optional>

Window color, in hexa: "#00aaee"

View Source client/ui/abstract/dataComponent.js, line 1084

# showFilterWindow(xopt, Yopt, coloropt)

Show a modal window to filter data

Parameters:
Name Type Attributes Description
x number <optional>

x coordinate

Y number <optional>

y coordinate

color string <optional>

Window color, in hexa: "#00aaee"

View Source client/ui/abstract/dataComponent.js, line 1124

# showMobileSearchBar()

Show the mobile search bar

View Source client/ui/abstract/dataComponent.js, line 1242

# showSearchBar()

Show the search bar

View Source client/ui/abstract/dataComponent.js, line 1146

# showSortWindow(xopt, Yopt, coloropt)

Show a modal window to sort data

Parameters:
Name Type Attributes Description
x number <optional>

x coordinate

Y number <optional>

y coordinate

color string <optional>

Window color, in hexa: "#00aaee"

View Source client/ui/abstract/dataComponent.js, line 1104

# async sortBy(sortFields)

Sort by an array of fields

Parameters:
Name Type Description
sortFields Array.<object>

Array where each object is a sort option, like: {firstName: "asc"}

View Source client/ui/abstract/dataComponent.js, line 320

Example
myDatatable.sortBy([
 {
     birthDate: "desc"
 },
 {
     lastName: "asc"
 }
])

# async sortByField(fieldId, direction)

Sort by a single field

Parameters:
Name Type Description
fieldId string
direction string

"asc" | "desc"

View Source client/ui/abstract/dataComponent.js, line 335

Example
myDatatable.sortByField("birthDate", "desc")

# toggleSelection()

Select / Deselect records

View Source client/ui/abstract/dataComponent.js, line 1453

# async updateConfig(update, needsDataReloadopt)

Update view configuration:

  • while offline, just reload
  • while online, check ACL prior to updating
  • if ACL check is successful, save the new configuration into db
Parameters:
Name Type Attributes Default Description
update object

The new configuration

needsDataReload boolean <optional>
true

If false, the data won't be reloaded. Default to true

View Source client/ui/abstract/dataComponent.js, line 618

# updateLocalConfig(update)

When the view configuration can't be persisted into db, we tried to store its parameters in the local storage.

Parameters:
Name Type Description
update object

View Source client/ui/abstract/dataComponent.js, line 672