Support for object-table v2 may be dropped in future versions of the JourneyApps Runtime. Please upgrade your app to use object-table v3 to ensure that your app remains compatible with the JourneyApps Runtime.
Version compatibility
object-table v2 was introduced in version 4.24.0 of the JourneyApps Container.
Top-level attributes
e.g.
<object-tablelimit="20" ...
Column-level attributes
e.g.
<columnsearch="true" ... />
Sorting
All columns are sortable. Click on a column header to sort it, and again to toggle ascending/descending order.
If a column consists solely of numbers, it will be sorted by numeric value. Similarly, if the column can be matched as a date, the date value is used instead of the display value. Finally, it is possible to specify a sort-value attribute (see table above) to override this default behavior when the display value no longer represents the underlying scalar value (for example the display value being: Percent: {number}%)
Mode
Version compatibility
This feature was introduced in version 4.27 of the JourneyApps Container.
Object tables have two possible modes:
paginate (Paginating mode) (default)
scroll (Fixed height mode)
Note that for each of the two modes, limit has a different function.
e.g.
<object-tablemode="scroll"limit="10" ... />
Row and Cell Formatting
Version compatibility
This feature was introduced in version 4.32 of the JourneyApps Container.
Row vs Cell styling
To style a specific cell, the property should be added to the <column> tag.
To style an entire row, the property should be added to the <object-table> tag.
Example:
<!-- Adding style-bold here will bold the entire row if shouldBeBold returns true for that row --><object-tablequery="transactions"style-bold="$:shouldBeBold($object)"> <columnheading="Title">{title}</column><!-- Adding style-background-color here styles each cell in the column individually --> <columnheading="Type"style-background-color="$:determineBackgroundColor($object)">{type}</column></object-table>
functiondetermineBackgroundColor(obj) {if (obj.type =='Income') {return'positive'; } else {// This is an expensereturn'negative'; }}
style=``
Styles can be computed programmatically using JavaScript/TypeScript.
Example:
functiongetStyle(obj) {// Return an object with all the same properties listed in the table above// Properties do not have `style-` in front of them// Camel-case is used instead of dashesreturn { align:'left', bold:true, italics:true, underline:true, strikethrough:true,// Colors can be hex or named color:'positive', backgroundColor:'positive', iconColor:'positive' };}
Notes:
Returning an empty object will apply no styling
Properties omitted from the returned object will not be affected
Editing Cells
Version compatibility
This feature was introduced in version 4.32 of the JourneyApps Container.
To make a cell editable, add an <edit- entry into the column. Valid options include edit-text, edit-number, edit-boolean, edit-date, edit-datetime and edit-select. They are explained in more detail below.
Display and edit flow
Example
<object-tablequery="users"><!-- The display value of the column moves into `display` --> <columnheading="Name"display="{name}"><!-- `value` is the initial value shown when the user edits the cell --><!-- `on-change` is run when the users is done changing the value --><!-- Note that $object is exposed here for quick referencing --> <edit-textvalue="$object.name"on-change="$:runOnChange($object, newValue, oldValue)" /> </column></object-table>
Properties on <edit-
Caveat: Prepend $: to the on-change function
If you return false from your on-change function, be sure to prepend $: to your on-change value, e.g. $:updateValue($object, newValue, oldValue). This allows JourneyApps to handle the returned value correctly.
Example
<object-tablequery="items"> <columnheading="Description">{description}</column><!-- Display the cost with a $ sign, e.g. $12 --> <columnheading="Cost"display="${cost}"><!-- When the user edits the number, don't display the $ sign, only 12 --> <edit-numbervalue="$object.cost"on-change="$:updateCost($object, newValue)" /> </column> </object-table>
functionupdateCost(obj, newValue, oldValue) {if (isValidCost(newValue)) {obj.cost = newValue;obj.save(); } else {notification.error("Invalid cost value"); // The cell will revert back to edit mode, allowing the user to correct the data that caused the validation error
returnfalse; }}
<edit- types
User Experience Tip: Specify an orderBy on your query
Since the default ordering for queries is by modification date, editing the value of an object's field via edit- will cause that object to be the last modified one. This causes your query to reload and the last modified object will be at the end of the list, creating the impression that it disappeared.
To prevent this from happening, be sure to specify an orderBy on your query on something other than the modification date, e.g. DB.user.all().orderBy('name'). This keeps the ordering stable, resulting in better user experience.
edit-select examples
Example 1
Simple string array
<object-tablequery="users"> <columnheading="Name"> {name} </column><!-- favorite_color is a string, one of: "Red", "Purple", "Blue", "Green", "Yellow" --> <columnheading="Favorite color"display="{favorite_color}"> <edit-select options="$:getColorOptions()" value="$object.favorite_color" on-change="$:updateFavoriteColor($object, newValue, oldValue)" />
</column> </object-table>
<object-tablequery="users"> <columnheading="Name"> {name} </column><!-- favorite_color is a string, one of: "r", "p", "b", "g", "y" --> <columnheading="Favorite color"display="{favorite_color}"><!-- Dropdown will display "Red", "Purple", "Blue", "Green", "Yellow" --> <edit-select options="$:getColorOptions()" value="$object.favorite_color" on-change="$:updateFavoriteColor($object, newValue, oldValue)" />
</column></object-table>
functiongetColorOptions() {return {'r':"Red",'p':"Purple",'b':"Blue",'g':"Green",'y':"Yellow" };}functionupdateFavoriteColor(obj, newValue, oldValue) {// newValue is one of "r", "p", "b", "g", "y"obj.favorite_color = newValue;obj.save();}
Cell-level actions
Version compatibility
This feature was introduced in version 4.32 of the JourneyApps Container.
To apply an action on a cell-click level, add an <action> to the <column> tag.
<object-table> <column><!-- `icon` is displayed on the right-hand-side of the cell --> <actionon-press="processAction($object)"icon="ion-chevron-right" /> </column></object-table>
This feature was introduced in version 4.34.6 of the JourneyApps Container.
Object Table Actions enable additional buttons to be appended to the controls area of an object table. Additionally, these buttons can call functions passing the current data in the object table.
Each of the buttons call a function in their on-press attribute with the following three parameters:
$filteredData: An object of the form {columns: string[], rows: DatabaseObject[]}. DatabaseObject refers to the familiar JourneyApps object that can be used to update values in the database.
filteredDisplayData: An object of the form {columns: string[], rows: string[][]}. The rows correspond to the text currently displayed in the table. This object can be directly passed to CSV's stringify function to create a CSV export of the table's data.
controls: An object of the form {page: number, totalPages: number, limit: number, filters: {string: string[]}}. This represents the current state of the search criteria and filters applied to the object table.
In both parameters where data is passed to the function the sort order and current table filters are applied to the data.
User Experience Tip: Use mode="split" on the button-group
When you have more than one button in the button-group and would like to emphasize one of them, use mode="split". This will display the first button in the group and place the rest in an Action Sheet.
Text. Where to place the controls (search bar, pagination controls).
Options include: top, bottom, both, none.
Defaults to bottomNote: When controls are set to none and the number of entries exceeds the limit, a "Show more" button will appear.
controls="top"
4.24.0
sticky-header
Boolean. Whether to freeze the header or not.
Defaults to false
sticky-header="true"
4.24.0
sticky-footer
Boolean. Whether to freeze the controls (when they display at the bottom)
Defaults to false
sticky-footer="true"
borderless
Boolean. Whether to display the outline borders or not.
Defaults to falseNote: Only applicable on mobile devices.
borderless="true"
4.24.0
smart-wrap
Boolean. Defaults to true
Set to false for cases where default wrapping in table is not optimal.
smart-wrap="true"
4.24.0
mode
Text. scroll or paginate. Defaults to paginate.
See Mode for more details
mode="scroll"
4.27.0
style, style-align, style-bold, etc.
Used to style an entire row given specific conditions.
See Row and Cell Formatting for more details.
style="$:determineStyle($object)"
4.32.0
default-filter
The default value for filter= on columns inside the object table.
default-filter="false"
4.40.5
default-sorting
The default value for sorting= on columns inside the object table.
default-sorting="false"
4.40.5
search
Boolean. Whether this column should be included when searching.
Default:
When no columns specify a search="true", all columns are included when searching.
When any column is set to search="true, columns without it are not included in when searching.
search="true"
4.24.0
show-if, hide-if
Controls whether the column is hidden or shown.
show-if="$:shouldShowColumn()"
4.26.1
style, style-align, style-bold, etc.
Used to style a cell given specific conditions.
See Row and Cell Formatting for more details.
style="$:determineStyle($object)"
4.32.0
icon
Adds an icon to the left-hand-side of a cell.
The icon can be a Font Awesome icon or an Ionicons icon. Defaults to no icon.
icon="ion-checkmark"
4.32.0
sort
Puts the column into a default sort mode regardless of the underlying query. (Useful to indicate which column is being sorted when cells are editable). Can either be asc or desc
sort="asc"
4.32.0
sort-value
The value to sort the column on instead of the display value. Useful when the display value would be something like: R{cost} but the column should sort only on cost
sort-value="$object.cost"
4.32.0
filter
Boolean.
Whether the column should be filterable. Defaults to true.
Note: Filters only available on Desktop containers.
filter="true"
4.32.0
sorting
Boolean
Whether the column is sortable. Defaults to true
sorting="false"
4.40.5
paginate
Data is loaded in pages, with controls to jump to the next or previous page.
The number of entries to display on a page
scroll
The data is loaded all at once, and the table itself is scrollable to reveal more data.
The height of the object table, measured in rows.
e.g. limit="10" will fix the table's height to the same height as 10 one-line rows.
style-align
The alignment of the text within the cell. left, right, center
Defaults to center
Object. Combination of these attributes, programatically determined by the JavaScript/TypeScript.
See section below for details.
style="$:getStyle($object)"
Initially
The object table will appear in a read-only (display) mode.
The value in display= is displayed.
As soon as the user taps or clicks on a cell
The cell will go into edit mode, allowing the user to modify the value.
The value in value= is shown to the user as the initial editing value.
After modifying the value, the user presses enter
The table goes back into display mode.
The function in on-change gets called and the value in display= gets recomputed and displayed.
value
The initial editing value.
Can either be:
$object.[field]
The result of a function, e.g. $:getInitialEditingValue($object)
value="$object.name"value="$:getName($object)"
on-change
The function to be called as soon as the user hits enter.
Note that $object, newValue and oldValue are exposed and can be passed to the function.
Note return false if the cell should not automatically deselect after the user has pressed enter. This can be used for validations.