mirror of https://github.com/nocodb/nocodb
2 changed files with 36 additions and 18 deletions
@ -0,0 +1,32 @@ |
|||||||
|
import type { ComputedRef, Ref } from 'vue' |
||||||
|
import type { PaginatedType, TableType } from 'nocodb-sdk' |
||||||
|
import { useNuxtApp } from '#app' |
||||||
|
import { useProject } from '~/composables/project' |
||||||
|
|
||||||
|
export const formatData = (list: Array<Record<string, any>>) => list.map(row => ({ |
||||||
|
row: { ...row }, |
||||||
|
oldRow: { ...row }, |
||||||
|
rowMeta: {}, |
||||||
|
})) |
||||||
|
|
||||||
|
export const useData = (meta: Ref<TableType> | ComputedRef<TableType>) => { |
||||||
|
const data = ref<Array<Record<string, any>>>() |
||||||
|
const formattedData = ref<Array<{ row: Record<string, any>; oldRow: Record<string, any> }>>() |
||||||
|
const paginationData = ref<PaginatedType>() |
||||||
|
|
||||||
|
const { project } = useProject() |
||||||
|
const { $api } = useNuxtApp() |
||||||
|
|
||||||
|
const loadData = async (params: { limit?: number; offset?: number; where?: string; sort?: string | string[]; fields?: string | string[] } = {}) => { |
||||||
|
const response = await $api.dbTableRow.list( |
||||||
|
'noco', |
||||||
|
project.value.id, |
||||||
|
meta.value.id, |
||||||
|
params as any, |
||||||
|
) |
||||||
|
data.value = response.list |
||||||
|
formattedData.value = formatData(response.list) |
||||||
|
} |
||||||
|
|
||||||
|
return { data, loadData, paginationData, formattedData } |
||||||
|
} |
Loading…
Reference in new issue