Skip to content

Commit

Permalink
Merge pull request #265 from balajidharma/fix/nested-sort-issue
Browse files Browse the repository at this point in the history
fix for sort issue with nested values
  • Loading branch information
HC200ok authored Mar 26, 2023
2 parents ab22975 + 49e64fe commit 5135908
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 40 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "HC200ok",
"description": "A customizable and easy-to-use data table component made with Vue.js 3.x.",
"private": false,
"version": "1.5.42",
"version": "1.5.43",
"types": "./types/main.d.ts",
"license": "MIT",
"files": [
Expand Down Expand Up @@ -59,5 +59,3 @@
"vue-tsc": "^0.34.7"
}
}


4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<ServerSideMode />
<!-- <ServerSideMode /> -->
<br><br>
<!-- <ClientMode /> -->
<ClientMode />
<br><br>
<!-- <ExpandLoading/> -->
</template>
Expand Down
61 changes: 30 additions & 31 deletions src/modes/Client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
multi-sort
body-text-direction="left"
header-text-direction="left"
:filter-options="filterOptions"
click-event-type="double"
@select-row="showItem"
@deselect-row="deselectRow"
@update-page-items="updateItems"
@update-total-items="updateTotalItems"
show-index-symbol="$"
>
<template #customize-headers>
<!-- <template #customize-headers>
<thead class="my-static-header">
<tr>
<th colspan="3" rowspan="2"></th>
Expand All @@ -64,7 +63,7 @@
<th>country</th>
</tr>
</thead>
</template>
</template> -->
<template #expand="item">
<div style="padding: 15px">
{{ item.name }} won championships
Expand Down Expand Up @@ -166,25 +165,25 @@ const updateTotalItems = (items: Item[]) => {
console.log(JSON.stringify(items));
};
// const items = ref<Item[]>([
// { name: "Stephen Curry", firstName: "GSW", number: 30, position: 'G', indicator: {"height": '6-2', "weight": 185}, lastAttended: "Davidson", country: "USA"},
// { name: "Kevin Durant", firstName: "BKN", number: 7, position: 'F', indicator: {"height": '6-10', "weight": 240}, lastAttended: "Texas-Austin", country: "USA"},
// { name: "Lebron James", firstName: "LAL", number: 7, position: 'F', indicator: {"height": '6-9', "weight": 185}, lastAttended: "St. Vincent-St. Mary HS (OH)", country: "USA"},
// { name: "Giannis Antetokounmpo", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 242}, lastAttended: "Filathlitikos", country: "Greece"},
// { name: "HC", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 243}, lastAttended: "Filathlitikos", country: "Greece"},
// { name: "Stephen Curry", firstName: "GSW", number: 30, position: 'G', indicator: {"height": '6-2', "weight": 185}, lastAttended: "Davidson", country: "USA"},
// { name: "Kevin Durant", firstName: "BKN", number: 7, position: 'F', indicator: {"height": '6-10', "weight": 240}, lastAttended: "Texas-Austin", country: "USA"},
// { name: "Lebron James", firstName: "LAL", number: 7, position: 'F', indicator: {"height": '6-9', "weight": 185}, lastAttended: "St. Vincent-St. Mary HS (OH)", country: "USA"},
// { name: "Giannis Antetokounmpo", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 242}, lastAttended: "Filathlitikos", country: "Greece"},
// { name: "HC", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 243}, lastAttended: "Filathlitikos", country: "Greece"},
// { name: "Stephen Curry", firstName: "GSW", number: 30, position: 'G', indicator: {"height": '6-2', "weight": 185}, lastAttended: "Davidson", country: "USA"},
// { name: "Kevin Durant", firstName: "BKN", number: 7, position: 'F', indicator: {"height": '6-10', "weight": 240}, lastAttended: "Texas-Austin", country: "USA"},
// { name: "Lebron James", firstName: "LAL", number: 7, position: 'F', indicator: {"height": '6-9', "weight": 185}, lastAttended: "St. Vincent-St. Mary HS (OH)", country: "USA"},
// { name: "Giannis Antetokounmpo", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 242}, lastAttended: "Filathlitikos", country: "Greece"},
// { name: "HC", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 243}, lastAttended: "Filathlitikos", country: "Greece"},
// ]);
const items = ref<Item[]>(mockClientItems());
const items = ref<Item[]>([
{ name: "Stephen Curry", firstName: "GSW", number: 30, position: 'G', indicator: {"height": '6-2', "weight": 185}, lastAttended: "Davidson", country: "USA"},
{ name: "Kevin Durant", firstName: "BKN", number: 7, position: 'F', indicator: {"height": '6-10', "weight": 240}, lastAttended: "Texas-Austin", country: "USA"},
{ name: "Lebron James", firstName: "LAL", number: 7, position: 'F', indicator: {"height": '6-9', "weight": 185}, lastAttended: "St. Vincent-St. Mary HS (OH)", country: "USA"},
{ name: "Giannis Antetokounmpo", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 242}, lastAttended: "Filathlitikos", country: "Greece"},
{ name: "HC", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 243}, lastAttended: "Filathlitikos", country: "Greece"},
{ name: "Stephen Curry", firstName: "GSW", number: 30, position: 'G', indicator: {"height": '6-2', "weight": 185}, lastAttended: "Davidson", country: "USA"},
{ name: "Kevin Durant", firstName: "BKN", number: 7, position: 'F', indicator: {"height": '6-10', "weight": 240}, lastAttended: "Texas-Austin", country: "USA"},
{ name: "Lebron James", firstName: "LAL", number: 7, position: 'F', indicator: {"height": '6-9', "weight": 185}, lastAttended: "St. Vincent-St. Mary HS (OH)", country: "USA"},
{ name: "Giannis Antetokounmpo", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 242}, lastAttended: "Filathlitikos", country: "Greece"},
{ name: "HC", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 243}, lastAttended: "Filathlitikos", country: "Greece"},
{ name: "Stephen Curry", firstName: "GSW", number: 30, position: 'G', indicator: {"height": '6-2', "weight": 185}, lastAttended: "Davidson", country: "USA"},
{ name: "Kevin Durant", firstName: "BKN", number: 7, position: 'F', indicator: {"height": '6-10', "weight": 240}, lastAttended: "Texas-Austin", country: "USA"},
{ name: "Lebron James", firstName: "LAL", number: 7, position: 'F', indicator: {"height": '6-9', "weight": 185}, lastAttended: "St. Vincent-St. Mary HS (OH)", country: "USA"},
{ name: "Giannis Antetokounmpo", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 242}, lastAttended: "Filathlitikos", country: "Greece"},
{ name: "HC", firstName: "MIL", number: 34, position: 'F', indicator: {"height": '6-11', "weight": 243}, lastAttended: "Filathlitikos", country: "Greece"},
]);
// const items = ref<Item[]>(mockClientItems());
// const headers: Header[] = [
// { text: 'Name', value: 'name'},
Expand Down Expand Up @@ -220,15 +219,15 @@ const favouriteSportCriteria = ref('all');
const showNameFilter = ref(false);
const nameCriteria = ref('');
const filterOptions = computed((): FilterOption[] => {
const filterOptionsArray: FilterOption[] = [];
filterOptionsArray.push({
field: 'name',
criteria: ['name-1', 'name-2'],
comparison: 'in',
});
return filterOptionsArray;
});
// const filterOptions = computed((): FilterOption[] => {
// const filterOptionsArray: FilterOption[] = [];
// filterOptionsArray.push({
// field: 'name',
// criteria: ['name-1', 'name-2'],
// comparison: 'in',
// });
// return filterOptionsArray;
// });
const bodyRowClassNameFunction: BodyRowClassNameFunction = (item: Item, index: number): string => (index === 0 ? 'first-row test-row' : '');
const bodyExpandRowClassNameFunction: BodyRowClassNameFunction = (item: Item, index: number): string => 'expand-row';
Expand Down
16 changes: 12 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import type { Item } from './types/main';

export function getItemValue(column: string, item: Item) {
if (column.includes('.')) {
let content: any = '';
const keys = column.split('.');
const { length } = keys;

let content;
let i = 0;

while (i < length) {
content = (i === 0 ? item[keys[i]] : content[keys[i]]);
if (i === 0) {
content = item[keys[0]];
} else if (content && typeof content === 'object') {
content = content[keys[i]];
} else {
content = '';
break;
}
i += 1;
if (content === undefined) break;
}
return content;
return content ?? '';
}
return item[column] ?? '';
}
Expand Down

0 comments on commit 5135908

Please sign in to comment.