|
58 | 58 | :size="size"
|
59 | 59 | @update:model-value="toggleAll"
|
60 | 60 | />
|
61 |
| - <span v-if="isReadOnly || !canSort">#</span> |
| 61 | + <span v-if="!canSort">#</span> |
62 | 62 | <ActionLink
|
63 | 63 | v-else
|
64 | 64 | :theme="theme || themeValues"
|
|
71 | 71 | >
|
72 | 72 | <span>#</span>
|
73 | 73 | <template v-if="!!ordering['id']">
|
74 |
| - <IconFa v-if="ordering.asc" name="arrow-down" /> |
75 |
| - <IconFa v-if="!ordering.asc" name="arrow-up" /> |
| 74 | + <IconFa v-if="ordering['id'] === 'asc'" name="arrow-down" /> |
| 75 | + <IconFa v-else name="arrow-up" /> |
76 | 76 | </template>
|
77 | 77 | </ActionLink>
|
78 | 78 | </div>
|
79 | 79 | </th>
|
80 | 80 | <td
|
81 |
| - v-for="(propertyName, propertyNameIndex) in propertiesMeta" |
82 |
| - :key="propertyNameIndex" |
| 81 | + v-for="(meta, metaIndex) in propertiesMeta" |
| 82 | + :key="metaIndex" |
83 | 83 | class="--maxWidth-440"
|
84 | 84 | :class="[
|
85 | 85 | `--txtSize-${size}`,
|
86 |
| - { ['is--selected']: canSort && !!ordering[propertyName.value] }, |
| 86 | + { ['is--selected']: meta.canSort && !!ordering[meta.value] }, |
87 | 87 | ]"
|
88 |
| - :data-column-name="propertyName.value" |
89 |
| - :data-column="propertyName.alias" |
| 88 | + :data-column-name="meta.value" |
| 89 | + :data-column="meta.alias" |
90 | 90 | :width="
|
91 |
| - extraCols && propertyNameIndex === propertiesMeta.length - 1 |
| 91 | + extraCols && metaIndex === propertiesMeta.length - 1 |
92 | 92 | ? '99%'
|
93 | 93 | : 'auto'
|
94 | 94 | "
|
95 | 95 | >
|
96 |
| - <span v-if="!canSort" :title="propertyName.value"> |
97 |
| - {{ propertyName.alias }} |
| 96 | + <span v-if="!meta.canSort" :title="meta.value"> |
| 97 | + {{ meta.alias }} |
98 | 98 | </span>
|
99 | 99 | <ActionLink
|
100 | 100 | v-else
|
101 | 101 | :theme="theme || themeValues"
|
102 |
| - :title="propertyName.value" |
103 |
| - :tooltip="t('table_sort_by_name', { name: propertyName.alias })" |
| 102 | + :title="meta.value" |
| 103 | + :tooltip="t('table_sort_by_name', { name: meta.alias })" |
104 | 104 | tooltip-as-text
|
105 | 105 | tooltip-position="bottom"
|
106 | 106 | :size="size"
|
107 |
| - @click="setOrdering(propertyName.value)" |
| 107 | + @click="setOrdering(meta.value)" |
108 | 108 | >
|
109 |
| - <span>{{ propertyName.alias }}</span> |
110 |
| - <template v-if="!!ordering[propertyName.value]"> |
111 |
| - <IconFa v-if="ordering.asc" name="arrow-down" /> |
| 109 | + <span>{{ meta.alias }}</span> |
| 110 | + <template v-if="!!ordering[meta.value]"> |
| 111 | + <IconFa |
| 112 | + v-if="ordering[meta.value] === 'asc'" |
| 113 | + name="arrow-down" |
| 114 | + /> |
112 | 115 | <IconFa v-else name="arrow-up" />
|
113 | 116 | </template>
|
114 | 117 | </ActionLink>
|
|
344 | 347 | iProperty,
|
345 | 348 | iSelectOption,
|
346 | 349 | tOrder,
|
| 350 | + tOrderBy, |
347 | 351 | tProps,
|
348 | 352 | tSizeModifier,
|
349 | 353 | } from "@open-xamu-co/ui-common-types";
|
|
388 | 392 | /**
|
389 | 393 | * Do nodes support pagination?
|
390 | 394 | */
|
391 |
| - canSort?: boolean; |
| 395 | + canSort?: boolean | tOrderBy; |
392 | 396 | /**
|
393 | 397 | * Function used to update a node
|
394 | 398 | */
|
|
467 | 471 | * TODO: require & use order getter fn instead
|
468 | 472 | */
|
469 | 473 | const ordering = computed(() => {
|
470 |
| - let orderBy: Record<string, tOrder> = { id: "desc" }; |
| 474 | + let [sortKey = "id", sortValue = "desc"] = Array.isArray(props.canSort) |
| 475 | + ? props.canSort |
| 476 | + : []; |
| 477 | +
|
| 478 | + let orderBy: Record<string, tOrder> = { [sortKey]: sortValue }; |
471 | 479 |
|
472 | 480 | if (router) {
|
473 | 481 | const route = router.currentRoute.value;
|
|
495 | 503 |
|
496 | 504 | interface iPropertyMeta extends iSelectOption {
|
497 | 505 | value: string;
|
| 506 | + canSort: boolean; |
498 | 507 | }
|
499 | 508 |
|
500 | 509 | /**
|
|
513 | 522 |
|
514 | 523 | return 0;
|
515 | 524 | })
|
516 |
| - .map(([key]): iPropertyMeta => { |
| 525 | + .map(([key, value]): iPropertyMeta => { |
517 | 526 | const options = (props.properties || []).map(toOption);
|
518 | 527 | const property = toOption(options.find((p) => p.value === key) || key);
|
519 | 528 | const aliasKey = _.snakeCase(key);
|
| 529 | + const canSort = typeof value === "string" || typeof value === "number"; |
520 | 530 |
|
521 | 531 | return {
|
522 | 532 | ...property,
|
523 | 533 | value: String(property.value),
|
524 | 534 | alias: _.capitalize(_.startCase(property.alias || tet(aliasKey))),
|
| 535 | + canSort: !!props.canSort && canSort, |
525 | 536 | };
|
526 | 537 | })
|
527 | 538 | .filter((property) => property.value !== "id");
|
|
0 commit comments