Skip to content

Commit

Permalink
Fix data table not doing external sorting
Browse files Browse the repository at this point in the history
Closes #33
  • Loading branch information
WarmCyan committed Aug 21, 2023
1 parent 7feb303 commit 5c26aa9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
9 changes: 9 additions & 0 deletions icat/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion icat/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _template(self):
<tbody :width="width">
<tr v-for="item in items" :key="item.id" @click="selectPoint(item.id)" @mouseover="hoverPoint(item.id)">
<td class="break-word" v-html="item.text" style="padding-left: 2px; padding-right: 2px;" />
<td style='vertical-align: top; padding-left: 2px; padding-right: 2px;' style="color: grey;">{{ item.id }}</td>
<td style="vertical-align: top; padding-left: 2px; padding-right: 2px; color: grey;">{{ item.id }}</td>
<td style="vertical-align: top; padding-bottom: 5px; padding-left: 2px;">
<v-btn x-small class="orange darken-1" @click.stop="applyAbsoluteLabelUninteresting(item.id)">
U
Expand Down
12 changes: 12 additions & 0 deletions notebooks/archive/Example3-Model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5c26aa9

Please sign in to comment.