diff --git a/package.json b/package.json index f335b93..755463e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/schema.json b/schema.json index ec333b3..b5992fc 100644 --- a/schema.json +++ b/schema.json @@ -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" } + ] } ] }, diff --git a/src/Component.svelte b/src/Component.svelte index a436df2..d898d86 100644 --- a/src/Component.svelte +++ b/src/Component.svelte @@ -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 @@ -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) @@ -89,7 +96,6 @@ _error = undefined try { _structure = JSON.parse(staticStructure) - console.log(_structure) } catch ( error ) { _error = " Error Parsing JSON "