Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
6ad83752
Unverified
Commit
6ad83752
authored
Feb 18, 2020
by
Torkel Ödegaard
Committed by
GitHub
Feb 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Table: Fixed header alignment (#22236)
parent
ff955622
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
+13
-6
packages/grafana-ui/src/components/Table/Table.tsx
+11
-6
packages/grafana-ui/src/components/Table/TableCell.tsx
+2
-0
No files found.
packages/grafana-ui/src/components/Table/Table.tsx
View file @
6ad83752
import
React
,
{
useMemo
}
from
'react'
;
import
{
DataFrame
}
from
'@grafana/data'
;
import
{
DataFrame
,
Field
}
from
'@grafana/data'
;
import
{
useSortBy
,
useTable
,
useBlockLayout
,
Cell
}
from
'react-table'
;
import
{
FixedSizeList
}
from
'react-window'
;
import
useMeasure
from
'react-use/lib/useMeasure'
;
...
...
@@ -8,6 +8,8 @@ import { useTheme } from '../../themes';
import
{
TableFilterActionCallback
}
from
'./types'
;
import
{
getTableStyles
}
from
'./styles'
;
import
{
TableCell
}
from
'./TableCell'
;
import
{
Icon
}
from
'../Icon/Icon'
;
import
{
getTextAlign
}
from
'./utils'
;
export
interface
Props
{
data
:
DataFrame
;
...
...
@@ -56,7 +58,9 @@ export const Table = ({ data, height, onCellClick, width }: Props) => {
<
div
>
{
headerGroups
.
map
((
headerGroup
:
any
)
=>
(
<
div
className=
{
tableStyles
.
thead
}
{
...
headerGroup
.
getHeaderGroupProps
()}
ref=
{
ref
}
>
{
headerGroup
.
headers
.
map
((
column
:
any
)
=>
renderHeaderCell
(
column
,
tableStyles
.
headerCell
))
}
{
headerGroup
.
headers
.
map
((
column
:
any
)
=>
renderHeaderCell
(
column
,
tableStyles
.
headerCell
,
data
.
fields
[
column
.
index
])
)
}
</
div
>
))
}
</
div
>
...
...
@@ -72,17 +76,18 @@ export const Table = ({ data, height, onCellClick, width }: Props) => {
);
};
function
renderHeaderCell
(
column
:
any
,
className
:
string
)
{
function
renderHeaderCell
(
column
:
any
,
className
:
string
,
field
:
Field
)
{
const
headerProps
=
column
.
getHeaderProps
(
column
.
getSortByToggleProps
());
const
fieldTextAlign
=
getTextAlign
(
field
);
if
(
column
.
t
extAlign
)
{
headerProps
.
style
.
textAlign
=
column
.
t
extAlign
;
if
(
fieldT
extAlign
)
{
headerProps
.
style
.
textAlign
=
fieldT
extAlign
;
}
return
(
<
div
className=
{
className
}
{
...
headerProps
}
>
{
column
.
render
(
'Header'
)
}
<
span
>
{
column
.
isSorted
?
(
column
.
isSortedDesc
?
' 🔽'
:
' 🔼'
)
:
''
}
</
span
>
{
column
.
isSorted
&&
(
column
.
isSortedDesc
?
<
Icon
name=
"caret-down"
/>
:
<
Icon
name=
"caret-up"
/>)
}
</
div
>
);
}
packages/grafana-ui/src/components/Table/TableCell.tsx
View file @
6ad83752
...
...
@@ -17,6 +17,7 @@ export const TableCell: FC<Props> = ({ cell, field, tableStyles, onCellClick })
const
cellProps
=
cell
.
getCellProps
();
let
onClick
:
((
event
:
React
.
SyntheticEvent
)
=>
void
)
|
undefined
=
undefined
;
if
(
filterable
&&
onCellClick
)
{
if
(
cellProps
.
style
)
{
cellProps
.
style
.
cursor
=
'pointer'
;
...
...
@@ -24,6 +25,7 @@ export const TableCell: FC<Props> = ({ cell, field, tableStyles, onCellClick })
onClick
=
()
=>
onCellClick
(
cell
.
column
.
Header
as
string
,
cell
.
value
);
}
const
fieldTextAlign
=
getTextAlign
(
field
);
if
(
fieldTextAlign
&&
cellProps
.
style
)
{
cellProps
.
style
.
textAlign
=
fieldTextAlign
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment