Skip to content

Commit

Permalink
Enable Item Sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
poirazis committed Jan 18, 2023
1 parent 6abf64e commit 6c05056
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bb-component-SuperSideNavigation",
"version": "1.2.0",
"version": "1.3.0",
"description": "A Side Navigation / Item List component for Budibase.",
"license": "MIT",
"author": "Michael Poirazi",
Expand Down
10 changes: 10 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
"label": "Item Column",
"key": "itemColumn",
"info": "Must be a Relationship Field"
},
{
"type": "select",
"key": "itemSorting",
"label" : "Sort Items",
"options" : [
{ "label" : "Ascending", "value": "ascending" },
{ "label" : "Descending", "value": "descending" },
{ "label" : "No Sorting", "value": "unsorted" }
]
}
]
},
Expand Down
8 changes: 7 additions & 1 deletion src/Component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let sectionColumnKey
export let sectionColumnValue
export let itemColumn
export let itemSorting
export let collapsible
export let allCollapsed
export let hideEmpty
Expand Down Expand Up @@ -80,6 +81,12 @@
element[itemColumn].forEach(itemElement => {
_section.items.push ( {"itemKey": itemElement._id, "itemValue": itemElement.primaryDisplay } );
});
if (itemSorting == "ascending" )
_section.items.sort((a,b) => (a.itemValue > b.itemValue) ? 1 : ((b.itemValue > a.itemValue) ? -1 : 0))
if (itemSorting == "descending" )
_section.items.sort((a,b) => (a.itemValue < b.itemValue) ? 1 : ((b.itemValue < a.itemValue) ? -1 : 0))
_structure.sections.push(_section);
console.log(_structure)
Expand All @@ -89,7 +96,6 @@
_error = undefined
try {
_structure = JSON.parse(staticStructure)
console.log(_structure)
} catch ( error )
{
_error = " Error Parsing JSON "
Expand Down

0 comments on commit 6c05056

Please sign in to comment.