Skip to content

Commit

Permalink
fix(VDataTable): readd missing disable-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
MajesticPotatoe committed May 16, 2024
1 parent d6b292f commit d18ca75
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/api-generator/src/locale/en/VDataTableHeader.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"props": {
"disableSort": "Toggles rendering of sort button.",
"everyItem": "Indicates if all items in table are selected.",
"headers": "Array of header items to display.",
"mobile": "Renders mobile view of headers.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"props": {
"disableSort": "Toggles rendering of sort button.",
"sortAscIcon": "Icon used for ascending sort button.",
"sortDescIcon": "Icon used for descending sort button.",
"sticky": "Sticks the header to the top of the table."
Expand Down
1 change: 1 addition & 0 deletions packages/api-generator/src/locale/en/VDataTableServer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"column.data-table-select": "Slot to replace the default `v-simple-checkbox` used when selecting rows.",
"dataTableGroup": "Slot for custom rendering of a group.",
"data-table-select": "Slot for custom rendering of a header cell with the select checkbox.",
"disableSort": "Disables sorting completely.",
"expanded-row": "Slot for custom rendering of an expanded row.",
"footer.prepend": "Adds content to the empty space in the footer.",
"group-header": "Slot for custom rendering of a group header.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"column.data-table-select": "Slot to replace the default `v-simple-checkbox` used when selecting rows.",
"data-table-group": "Slot for custom rendering of a group.",
"data-table-select": "Slot for custom rendering of a header cell with the select checkbox.",
"disableSort": "Disables sorting completely.",
"expanded-row": "Slot for custom rendering of an expanded row.",
"group-header": "Slot for custom rendering of a group header.",
"headers": "Slot to replace the default rendering of the `<thead>` element.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type VDataTableHeadersSlots = {
export const makeVDataTableHeadersProps = propsFactory({
color: String,
sticky: Boolean,
disableSort: Boolean,
multiSort: Boolean,
sortAscIcon: {
type: IconValue,
Expand Down Expand Up @@ -142,7 +143,7 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
align={ column.align }
class={[
{
'v-data-table__th--sortable': column.sortable,
'v-data-table__th--sortable': column.sortable && !props.disableSort,
'v-data-table__th--sorted': isSorted(column),
'v-data-table__th--fixed': column.fixed,
},
Expand Down Expand Up @@ -192,7 +193,7 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
return (
<div class="v-data-table-header__content">
<span>{ column.title }</span>
{ column.sortable && (
{ column.sortable && !props.disableSort && (
<VIcon
key="icon"
class="v-data-table-header__sort-icon"
Expand Down Expand Up @@ -223,7 +224,7 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
const headerProps = mergeProps(props.headerProps ?? {} ?? {})

const displayItems = computed<ItemProps['items']>(() => {
return columns.value.filter(column => column?.sortable)
return columns.value.filter(column => column?.sortable && !props.disableSort)
})

const appendIcon = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ export function useSort () {
}

// TODO: abstract into project composable
export function useSortedItems <T extends InternalItem> (
props: { customKeySort: Record<string, DataTableCompareFunction> | undefined },
export function useSortedItems<T extends InternalItem> (
props: {
customKeySort: Record<string, DataTableCompareFunction> | undefined
disableSort?: Boolean
},
items: Ref<T[]>,
sortBy: Ref<readonly SortItem[]>,
options?: {
Expand All @@ -107,7 +110,7 @@ export function useSortedItems <T extends InternalItem> (
) {
const locale = useLocale()
const sortedItems = computed(() => {
if (!sortBy.value.length) return items.value
if (!sortBy.value.length || props.disableSort) return items.value

return sortItems(items.value, sortBy.value, locale.current.value, {
transform: options?.transform,
Expand Down

0 comments on commit d18ca75

Please sign in to comment.