Table
useTableCore
Composable interno con funzionalita core condivise tra DataTable e TreeTable (accesso nested, row key, classi CSS).
Composable interno — utilizzato dai componenti
DataTableeTreeTabledella libreria.
Firma TypeScript
export function useTableCore(options: UseTableCoreOptions): UseTableCoreResult
// UseTableCoreOptions (da @/types/basetable)
interface UseTableCoreOptions {
dataKey?: string; // default: 'id'
stripedRows?: boolean; // default: false
showGridlines?: boolean; // default: false
scrollable?: boolean; // default: false
scrollHeight?: string; // default: '400px'
size?: Size; // default: 'medium'
loading?: boolean; // default: false
showHeader?: boolean; // default: true
rowHover?: boolean; // default: true
componentPrefix?: string; // default: 'table'
}
export interface UseTableCoreResult {
getNestedValue: (obj: unknown, path: string) => unknown;
getRowKey: (row: unknown, index: number) => string | number;
tableClasses: ComputedRef<string[]>;
wrapperStyle: ComputedRef<Record<string, string>>;
}
Parametri
| Parametro | Tipo | Default | Descrizione |
|---|---|---|---|
dataKey | string | 'id' | Proprieta usata come chiave univoca delle righe |
stripedRows | boolean | false | Aggiunge classe striped |
showGridlines | boolean | false | Aggiunge classe gridlines |
scrollable | boolean | false | Abilita scroll verticale |
scrollHeight | string | '400px' | Altezza massima per lo scroll |
size | Size | 'medium' | Dimensione righe (small, medium, large) |
loading | boolean | false | Aggiunge classe loading |
componentPrefix | string | 'table' | Prefisso per le classi CSS generate |
Valore di Ritorno
| Proprietà | Tipo | Descrizione |
|---|---|---|
getNestedValue | (obj, path) => unknown | Accede a proprieta nested con dot notation (es. 'user.name') |
getRowKey | (row, index) => string | number | Ritorna row[dataKey] o index come fallback |
tableClasses | ComputedRef<string[]> | Array di classi CSS per il container della tabella |
wrapperStyle | ComputedRef<Record<string, string>> | Stile inline per scroll ({ maxHeight, overflow } se scrollable) |
Esempio
const { getNestedValue, getRowKey, tableClasses, wrapperStyle } = useTableCore({
dataKey: 'id',
stripedRows: true,
size: 'medium',
componentPrefix: 'datatable'
})
// Accesso valore nested
const name = getNestedValue(row, 'user.profile.name')
// Chiave tracking v-for
const key = getRowKey(row, index)
Note
getNestedValuesupporta qualsiasi profondita di dot notation; ritornaundefinedse un segmento non esiste.tableClassesinclude solo le classi non-default:size-small/size-largema nonsize-medium(classe implicita).wrapperStyleritorna{}sescrollable=false, quindi e sicuro applicarlo sempre con:style="wrapperStyle".