diff --git a/CHANGELOG.md b/CHANGELOG.md index d0cb40f..f83c242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [unreleased] + +### Fixed +* Data column sorting not working. + + + + ## [0.4.0] - 2023-08-18 ### Added diff --git a/README.md b/README.md index b7fdcea..c53da18 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![PyPI version](https://badge.fury.io/py/icat-iml.svg)](https://badge.fury.io/py/icat-iml) [![tests](https://github.com/ORNL/icat/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/ORNL/icat/actions/workflows/tests.yml) +[![License](https://img.shields.io/pypi/l/curifactory)](https://github.com/ORNL/curifactory/blob/main/LICENSE) diff --git a/icat/data.py b/icat/data.py index f76e833..1147507 100644 --- a/icat/data.py +++ b/icat/data.py @@ -451,6 +451,15 @@ def _set_page_contents(self, options): if "itemsPerPage" in options: count = options["itemsPerPage"] + # sort the dataframe if requested (has to be done here since data external to JS) + if "sortBy" in options and len(options["sortBy"]) > 0: + if options["sortBy"][0] == "index": + df = df.sort_index(ascending=(not options["sortDesc"][0])) + else: + df = df.sort_values( + by=options["sortBy"][0], ascending=(not options["sortDesc"][0]) + ) + # calculate the range in the dataframe based on current page total_len = df.shape[0] end_index = page_num * count diff --git a/icat/table.py b/icat/table.py index 8ebc24c..9f6e6f3 100644 --- a/icat/table.py +++ b/icat/table.py @@ -132,7 +132,7 @@ def _template(self): - {{ item.id }} + {{ item.id }} U diff --git a/notebooks/archive/Example3-Model.ipynb b/notebooks/archive/Example3-Model.ipynb index 178818a..27164c3 100644 --- a/notebooks/archive/Example3-Model.ipynb +++ b/notebooks/archive/Example3-Model.ipynb @@ -84,6 +84,18 @@ "model.view" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5002157-64d9-4643-a2bd-a1b14e402712", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "model.data.filtered_df.sort_index(ascending=False)" + ] + }, { "cell_type": "code", "execution_count": null,