Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/vuetify/src/labs/VDataIterator/VDataIterator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const VDataIterator = genericComponent<VDataIteratorSlots>()({
emits: {
'update:modelValue': (value: any[]) => true,
'update:groupBy': (value: any) => true,
'update:groupExpanded': (value: any) => true,
'update:page': (value: number) => true,
'update:itemsPerPage': (value: number) => true,
'update:sortBy': (value: any) => true,
Expand All @@ -81,6 +82,7 @@ export const VDataIterator = genericComponent<VDataIteratorSlots>()({

setup (props, { slots }) {
const groupBy = useProxiedModel(props, 'groupBy')
const groupExpanded = useProxiedModel(props, 'groupExpanded')
const search = toRef(props, 'search')

const { items } = useDataIteratorItems(props)
Expand All @@ -93,7 +95,7 @@ export const VDataIterator = genericComponent<VDataIteratorSlots>()({
const { sortByWithGroups, opened, extractRows, isGroupOpen, toggleGroup } = provideGroupBy({ groupBy, sortBy })

const { sortedItems } = useSortedItems(props, filteredItems, sortByWithGroups)
const { flatItems } = useGroupedItems(sortedItems, groupBy, opened)
const { flatItems } = useGroupedItems(sortedItems, groupBy, opened, groupExpanded)

const itemsLength = computed(() => flatItems.value.length)

Expand Down
5 changes: 3 additions & 2 deletions packages/vuetify/src/labs/VDataTable/VDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ export const VDataTable = genericComponent<VDataTableSlots>()({
'update:sortBy': (value: any) => true,
'update:options': (value: any) => true,
'update:groupBy': (value: any) => true,
'update:groupExpanded': (value: any) => true,
'update:expanded': (value: any) => true,
},

setup (props, { emit, slots }) {
const { groupBy } = createGroupBy(props)
const { groupBy, groupExpanded } = createGroupBy(props)
const { sortBy, multiSort, mustSort } = createSort(props)
const { page, itemsPerPage } = createPagination(props)

Expand All @@ -123,7 +124,7 @@ export const VDataTable = genericComponent<VDataTableSlots>()({
const { sortByWithGroups, opened, extractRows, isGroupOpen, toggleGroup } = provideGroupBy({ groupBy, sortBy })

const { sortedItems } = useSortedItems(props, filteredItems, sortByWithGroups)
const { flatItems } = useGroupedItems(sortedItems, groupBy, opened)
const { flatItems } = useGroupedItems(sortedItems, groupBy, opened, groupExpanded)
const itemsLength = computed(() => flatItems.value.length)

const { startIndex, stopIndex, pageCount, setItemsPerPage } = providePagination({ page, itemsPerPage, itemsLength })
Expand Down
5 changes: 3 additions & 2 deletions packages/vuetify/src/labs/VDataTable/VDataTableServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export const VDataTableServer = genericComponent<VDataTableSlots>()({
'update:options': (options: any) => true,
'update:expanded': (options: any) => true,
'update:groupBy': (value: any) => true,
'update:groupExpanded': (value: any) => true,
},

setup (props, { emit, slots }) {
const { groupBy } = createGroupBy(props)
const { groupBy, groupExpanded } = createGroupBy(props)
const { sortBy, multiSort, mustSort } = createSort(props)
const { page, itemsPerPage } = createPagination(props)
const itemsLength = computed(() => parseInt(props.itemsLength, 10))
Expand All @@ -69,7 +70,7 @@ export const VDataTableServer = genericComponent<VDataTableSlots>()({

const { pageCount, setItemsPerPage } = providePagination({ page, itemsPerPage, itemsLength })

const { flatItems } = useGroupedItems(items, groupBy, opened)
const { flatItems } = useGroupedItems(items, groupBy, opened, groupExpanded)

const { isSelected, select, selectAll, toggleSelect, someSelected, allSelected } = provideSelection(props, {
allItems: items,
Expand Down
5 changes: 3 additions & 2 deletions packages/vuetify/src/labs/VDataTable/VDataTableVirtual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ export const VDataTableVirtual = genericComponent<VDataTableVirtualSlots>()({
'update:sortBy': (value: any) => true,
'update:options': (value: any) => true,
'update:groupBy': (value: any) => true,
'update:groupExpanded': (value: any) => true,
'update:expanded': (value: any) => true,
},

setup (props, { emit, slots }) {
const { groupBy } = createGroupBy(props)
const { groupBy, groupExpanded } = createGroupBy(props)
const { sortBy, multiSort, mustSort } = createSort(props)

const { columns, headers } = createHeaders(props, {
Expand All @@ -78,7 +79,7 @@ export const VDataTableVirtual = genericComponent<VDataTableVirtualSlots>()({
const { sortByWithGroups, opened, extractRows, isGroupOpen, toggleGroup } = provideGroupBy({ groupBy, sortBy })

const { sortedItems } = useSortedItems(props, filteredItems, sortByWithGroups)
const { flatItems } = useGroupedItems(sortedItems, groupBy, opened)
const { flatItems } = useGroupedItems(sortedItems, groupBy, opened, groupExpanded)

const allItems = computed(() => extractRows(flatItems.value))

Expand Down
24 changes: 18 additions & 6 deletions packages/vuetify/src/labs/VDataTable/composables/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const makeDataTableGroupProps = propsFactory({
type: Array as PropType<readonly SortItem[]>,
default: () => ([]),
},
groupExpanded: {
type: Boolean,
default: () => false,
},
}, 'DataTable-group')

const VDataTableGroupSymbol: InjectionKey<{
Expand All @@ -43,12 +47,15 @@ const VDataTableGroupSymbol: InjectionKey<{
type GroupProps = {
groupBy: readonly SortItem[]
'onUpdate:groupBy': ((value: SortItem[]) => void) | undefined
groupExpanded: Boolean
'onUpdate:groupExpanded': ((value: boolean) => void) | undefined
}

export function createGroupBy (props: GroupProps) {
const groupBy = useProxiedModel(props, 'groupBy')
const groupExpanded = useProxiedModel(props, 'groupExpanded')

return { groupBy }
return { groupBy, groupExpanded }
}

export function provideGroupBy (options: { groupBy: Ref<readonly SortItem[]>, sortBy: Ref<readonly SortItem[]> }) {
Expand Down Expand Up @@ -151,7 +158,11 @@ function groupItems <T extends GroupableItem> (items: readonly T[], groupBy: rea
return groups
}

function flattenItems <T extends GroupableItem> (items: readonly (T | Group<T>)[], opened: Set<string>): readonly (T | Group<T>)[] {
function flattenItems <T extends GroupableItem> (
items: readonly (T | Group<T>)[],
opened: Set<string>,
groupExpanded: Boolean): readonly (T | Group<T>
)[] {
const flatItems: (T | Group<T>)[] = []

for (const item of items) {
Expand All @@ -161,8 +172,8 @@ function flattenItems <T extends GroupableItem> (items: readonly (T | Group<T>)[
flatItems.push(item)
}

if (opened.has(item.id) || item.value == null) {
flatItems.push(...flattenItems(item.items, opened))
if (opened.has(item.id) || item.value == null || groupExpanded) {
flatItems.push(...flattenItems(item.items, opened, groupExpanded))
}
} else {
flatItems.push(item)
Expand All @@ -175,14 +186,15 @@ function flattenItems <T extends GroupableItem> (items: readonly (T | Group<T>)[
export function useGroupedItems <T extends GroupableItem> (
items: Ref<T[]>,
groupBy: Ref<readonly SortItem[]>,
opened: Ref<Set<string>>
opened: Ref<Set<string>>,
groupExpanded: Ref<Boolean>
) {
const flatItems = computed(() => {
if (!groupBy.value.length) return items.value

const groupedItems = groupItems(items.value, groupBy.value.map(item => item.key))

return flattenItems(groupedItems, opened.value)
return flattenItems(groupedItems, opened.value, groupExpanded.value)
})

return { flatItems }
Expand Down