Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display start/enddate and make sortable table #320

Merged
merged 3 commits into from
May 31, 2024
Merged

Display start/enddate and make sortable table #320

merged 3 commits into from
May 31, 2024

Conversation

sravfeyn
Copy link
Member

@sravfeyn sravfeyn commented May 2, 2024

{% block inline_javascript %}
{{ block.super }}
<script>
function sortableTable() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could of course do this using jQuery datatables but that will add few JS dependencies. So this is done without any dependencies using AlpineJS.

@pxwxnvermx pxwxnvermx requested review from calellowitz and removed request for cws1121 May 6, 2024 12:19
@sravfeyn
Copy link
Member Author

sravfeyn commented May 9, 2024

@calellowitz FYI

Copy link
Collaborator

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple questions but only one major one.

@@ -3,6 +3,63 @@

{% block title %}{{ request.org }} - Opportunities{% endblock %}

{% block inline_javascript %}
{{ block.super }}
<script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make this more reusable, since we will likely need sortable columns in other tables

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought of that, but didn't do it prematurely. We can take this out when we add another similar feature.

@@ -15,19 +72,23 @@ <h1> Opportunities
</span>
</h1>
</div>
<div class="pb-4">
<div class="pb-4" x-data="sortableTable()">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it will only sort the items displayed, but for paginated data, you won't get the true first X items. I think this might need to be implemented like the paginations controls, to rerender the table, and fetch the data from the backend. That likely makes the final implementation simpler (since you won't need much js, just click functions that make ajax calls). Let me know if I am misunderstanding how this works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it will only sort the items displayed, but for paginated data, you won't get the true first X items.

Yes, that's right. This sorts client side data only. The server side sorting could be done, but it's entirely different approach and does need much rework. My understanding of the ticket was that they were looking for client side sorting.

<table class="table border table-responsive">
<thead class="table-light">
<tr>
<th>Name</th>
<th @click="sortByColumn" role="button">Name <i class="bi bi-arrow-down-short"></i></th>
<th @click="sortByColumn" role="button">Start Date <i class="bi bi-arrow-down-short"></i></th>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the arrow switch direction when the columns are sorted in the opposite order?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, apparently that requires good amount of Javascript and CSS. Best handled by libraries such as datatable

@sravfeyn
Copy link
Member Author

@calellowitz I have updated the sorting to be done on server side. I have updated the screenshot too.

Copy link
Collaborator

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better. Thanks for making these changes. One potential change but nothing blocking

# Construct the URL with the new sorting parameter
url = f"{request.path}?sort={new_sort}"
if request.GET.get("page"):
url += f"&page={request.GET.get('page')}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you change the sorting it should probably go back to page 1 (it is unintuitive to start on page 3 of a different sort)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sravfeyn sravfeyn merged commit 1fbd2fe into main May 31, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants