Skip to content

Commit

Permalink
Fix issue with numbers in the table and rooms sort
Browse files Browse the repository at this point in the history
  • Loading branch information
startsev2000 committed Sep 27, 2024
1 parent ec28565 commit 66362f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
7 changes: 4 additions & 3 deletions front-end/src/components/Personnel/Students/Students.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
scrollable
scroll-height="600px"
:value="students"
:sort-field="fullname"
:sort-field="milgroupField"
:sort-order="1"
class="p-datatable-striped p-datatable-gridlines p-datatable-sm"
:row-class="() => 'clickable'"
Expand All @@ -73,9 +73,10 @@
header-style="width: 68px"
body-style="width: 68px"
column-key="index"
:sortable="false"
>
<template #body="{ data }">
{{ students.indexOf(data) + 1 }}
<template #body="{ index }">
{{ index + 1 }}
</template>
</PrimeColumn>
<PrimeColumn
Expand Down
29 changes: 28 additions & 1 deletion front-end/src/store/modules/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,34 @@ class Reference extends VuexModule {
return await getFetchRequest(
getRooms,
data => {
data.sort((a, b) => a - b);
console.log(data);
data.sort((a, b) => {
const titleA = a.title;
const titleB = b.title;

const numA = Number(titleA);
const numB = Number(titleB);

const isNumA = !Number.isNaN(numA);
const isNumB = !Number.isNaN(numB);

if (isNumA && isNumB) {
return numA - numB;
}

if (isNumA) {
return -1;
}

if (isNumB) {
return 1;
}

if (titleA < titleB) { return -1; }
if (titleA > titleB) { return 1; }

return titleA.localeCompare(titleB);
});
this.SET_ROOMS(data);
this.SET_IS_LOADED({ field: "_roomsLoaded", value: true });
},
Expand Down

0 comments on commit 66362f2

Please sign in to comment.