Skip to content

feat: create way to change the text align of each header/column #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions src/components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<span
v-else
class="header"
:class="`direction-${headerTextDirection}`"
:class="[header.textAlign ? `direction-${header.textAlign}` : `direction-${headerTextDirection}`]"
>
<slot
v-if="slots[`header-${header.value}`]"
Expand All @@ -73,7 +73,7 @@
v-else-if="slots['header']"
name="header"
v-bind="header"
/>
/>
<span
v-else
class="header-text"
Expand Down Expand Up @@ -143,7 +143,9 @@
'shadow': column === lastFixedColumn,
'can-expand': column === 'expand',
// eslint-disable-next-line max-len
}, typeof bodyItemClassName === 'string' ? bodyItemClassName : bodyItemClassName(column, index + 1), `direction-${bodyTextDirection}`]"
}, typeof bodyItemClassName === 'string' ? bodyItemClassName : bodyItemClassName(column, index + 1),
getTextAlign(column)
]"
@click="column === 'expand' ? updateExpandingItemIndexList(index + prevPageEndIndex, item, $event) : null"
>
<slot
Expand Down Expand Up @@ -569,6 +571,12 @@ const getFixedDistance = (column: string, type: 'td' | 'th' = 'th') => {
return undefined;
};

const getTextAlign = (column: string): string | undefined => {
const header = headersForRender.value.find((header) => header.value === column)
const align = header?.textAlign || bodyTextDirection.value
return align ? `direction-${align}` : undefined
}

watch(loading, (newVal, oldVal) => {
if (serverOptionsComputed.value) {
// in server-side mode, turn to next page when api request finished.
Expand Down
3 changes: 2 additions & 1 deletion src/types/internal.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SortType } from './main';
import type { SortType, TextDirection } from './main';

export type ServerOptionsComputed = {
page: number
Expand All @@ -14,6 +14,7 @@ export type HeaderForRender = {
sortType?: SortType | 'none',
fixed?: Boolean,
width?: number,
textAlign?: TextDirection
}

export type ClientSortOptions = {
Expand Down
1 change: 1 addition & 0 deletions src/types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type Header = {
sortable?: boolean
fixed?: boolean
width?: number
textAlign?: TextDirection
}

export type ServerOptions = {
Expand Down
1 change: 1 addition & 0 deletions types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type Header = {
sortable?: boolean
fixed?: boolean
width?: number
textAlign?: TextDirection
}

export type ServerOptions = {
Expand Down