@@ -13,8 +13,8 @@ object TableStaticDemo {
13
13
def datum (data : List [DataRow ])(i : Int ) = data(i % data.length)
14
14
def rowheight (data : List [DataRow ])(i : Int ) = datum(data)(i).size
15
15
16
- final case class Props (useDynamicRowHeight : Boolean , sortBy : String , s : Size )
17
- final case class State (sortDirection : SortDirection , data : List [DataRow ])
16
+ final case class Props (useDynamicRowHeight : Boolean , sortBy : String , s : Size )
17
+ final case class State (sortDirection : SortDirection , data : List [DataRow ])
18
18
19
19
def headerRenderer (sortBy : String )(
20
20
columnData : DataRow ,
@@ -26,11 +26,12 @@ object TableStaticDemo {
26
26
): VdomNode =
27
27
< .div(" Full Name" , SortIndicator (SortDirection .ASC ).when(sortBy == dataKey))
28
28
29
- def rowClassName (i : Int ): String = i match {
30
- case x if x < 0 => " headerRow"
31
- case x if x % 2 == 0 => " evenRow"
32
- case _ => " oddRow"
33
- }
29
+ def rowClassName (i : Int ): String =
30
+ i match {
31
+ case x if x < 0 => " headerRow"
32
+ case x if x % 2 == 0 => " evenRow"
33
+ case _ => " oddRow"
34
+ }
34
35
35
36
val component = ScalaComponent
36
37
.builder[Props ](" TableStaticDemo" )
@@ -39,8 +40,9 @@ object TableStaticDemo {
39
40
def sort (index : String , sortDirection : SortDirection ): Callback = {
40
41
val sorted = state.data.sortBy(_.index)
41
42
$.setState(
42
- state.copy(data = if (sortDirection == SortDirection .ASC ) sorted else sorted.reverse,
43
- sortDirection = sortDirection)
43
+ state.copy(data = if (sortDirection == SortDirection .ASC ) sorted else sorted.reverse,
44
+ sortDirection = sortDirection
45
+ )
44
46
)
45
47
}
46
48
val columns = List (
@@ -54,33 +56,33 @@ object TableStaticDemo {
54
56
210 ,
55
57
" random" ,
56
58
disableSort = true ,
57
- className = " exampleColumn" ,
58
- label = " The description label is so long it will be truncated" ,
59
- flexGrow = 1 ,
59
+ className = " exampleColumn" ,
60
+ label = " The description label is so long it will be truncated" ,
61
+ flexGrow = 1 ,
60
62
cellRenderer =
61
63
(cellData : DataRow , _ : js.Any , _ : String , _ : js.Any , _ : Int ) => cellData.toString
62
64
)
63
65
)
64
66
)
65
67
Table (
66
68
Table .props(
67
- disableHeader = false ,
68
- noRowsRenderer = () => < .div(^ .cls := " noRows" , " No rows" ),
69
+ disableHeader = false ,
70
+ noRowsRenderer = () => < .div(^ .cls := " noRows" , " No rows" ),
69
71
overscanRowCount = 10 ,
70
- rowClassName = rowClassName _,
71
- height = 270 ,
72
- rowCount = 1000 ,
73
- rowHeight = if (props.useDynamicRowHeight) rowheight(state.data) _ else 40 ,
74
- onRowClick = x => Callback .log(x),
75
- onScroll = (c, s, t) => Callback .log(s " $c $s $t" ),
76
- width = scala.math.max(1 , props.s.width.toInt),
77
- rowGetter = datum(state.data),
78
- headerClassName = " headerColumn" ,
79
- sort = sort _,
80
- sortBy = props.sortBy,
81
- sortDirection = state.sortDirection,
82
- scrollTop = 2000 ,
83
- headerHeight = 30
72
+ rowClassName = rowClassName _,
73
+ height = 270 ,
74
+ rowCount = 1000 ,
75
+ rowHeight = if (props.useDynamicRowHeight) rowheight(state.data) _ else 40 ,
76
+ onRowClick = x => Callback .log(x),
77
+ onScroll = (c, s, t) => Callback .log(s " $c $s $t" ),
78
+ width = scala.math.max(1 , props.s.width.toInt),
79
+ rowGetter = datum(state.data),
80
+ headerClassName = " headerColumn" ,
81
+ sort = sort _,
82
+ sortBy = props.sortBy,
83
+ sortDirection = state.sortDirection,
84
+ scrollTop = 2000 ,
85
+ headerHeight = 30
84
86
),
85
87
columns : _*
86
88
)
@@ -99,8 +101,8 @@ object TableDynamicDemo {
99
101
def datum (data : List [DataRow ])(i : Int ) = data(i % data.length)
100
102
def rowheight (data : List [DataRow ])(i : Int ) = datum(data)(i).size
101
103
102
- final case class Props (useDynamicRowHeight : Boolean , sortBy : String , s : Size )
103
- final case class State (sortDirection : SortDirection , data : List [DataRow ])
104
+ final case class Props (useDynamicRowHeight : Boolean , sortBy : String , s : Size )
105
+ final case class State (sortDirection : SortDirection , data : List [DataRow ])
104
106
105
107
def headerRenderer (sortBy : String )(
106
108
columnData : DataRow ,
@@ -112,21 +114,22 @@ object TableDynamicDemo {
112
114
): VdomNode =
113
115
< .div(" Full Name" , SortIndicator (SortDirection .ASC ).when(sortBy == dataKey))
114
116
115
- def rowClassName (i : Int ): String = i match {
116
- case x if x < 0 => " headerRow"
117
- case x if x % 2 == 0 => " evenRow"
118
- case _ => " oddRow"
119
- }
117
+ def rowClassName (i : Int ): String =
118
+ i match {
119
+ case x if x < 0 => " headerRow"
120
+ case x if x % 2 == 0 => " evenRow"
121
+ case _ => " oddRow"
122
+ }
120
123
121
124
val dynamicCellRenderer : CellRenderer [DataRow , js.Object , js.Object ] =
122
125
(cellData : DataRow , _ : js.Object , _ : String , _ : js.Object , rowIndex : Int ) => {
123
126
CellMeasurer (
124
127
CellMeasurer .props(
125
- cache = TableCache .cache,
126
- parent = CellMeasurer .Parent .Zero ,
128
+ cache = TableCache .cache,
129
+ parent = CellMeasurer .Parent .Zero ,
127
130
columnIndex = 2 ,
128
- rowIndex = rowIndex,
129
- children = < .div(cellData.toString)
131
+ rowIndex = rowIndex,
132
+ children = < .div(cellData.toString)
130
133
)
131
134
)
132
135
}
@@ -139,8 +142,9 @@ object TableDynamicDemo {
139
142
def sort (index : String , sortDirection : SortDirection ): Callback = {
140
143
val sorted = state.data.sortBy(_.index)
141
144
$.setState(
142
- state.copy(data = if (sortDirection == SortDirection .ASC ) sorted else sorted.reverse,
143
- sortDirection = sortDirection)
145
+ state.copy(data = if (sortDirection == SortDirection .ASC ) sorted else sorted.reverse,
146
+ sortDirection = sortDirection
147
+ )
144
148
)
145
149
}
146
150
val columns = List (
@@ -153,34 +157,34 @@ object TableDynamicDemo {
153
157
Column .props(
154
158
TableCache .cache.getWidth(2 ),
155
159
" random" ,
156
- disableSort = true ,
157
- className = " exampleColumn" ,
158
- label = " The description label is so long it will be truncated" ,
159
- flexGrow = 1 ,
160
+ disableSort = true ,
161
+ className = " exampleColumn" ,
162
+ label = " The description label is so long it will be truncated" ,
163
+ flexGrow = 1 ,
160
164
cellRenderer = dynamicCellRenderer
161
165
)
162
166
)
163
167
)
164
168
val t = Table (
165
169
Table .props(
166
170
deferredMeasurementCache = TableCache .cache,
167
- disableHeader = false ,
168
- noRowsRenderer = () => < .div(^ .cls := " noRows" , " No rows" ),
169
- overscanRowCount = 10 ,
170
- rowClassName = rowClassName _,
171
- height = 600 ,
172
- rowCount = 10 ,
173
- rowHeight = TableCache .cache.rowHeight.toScala,
174
- onRowClick = x => Callback .log(x),
175
- onScroll = (c, s, t) => Callback .log(s " $c $s $t" ),
176
- width = props.s.width.toInt,
177
- rowGetter = datum(state.data),
178
- headerClassName = " headerColumn" ,
179
- sort = sort _,
180
- sortBy = props.sortBy,
181
- sortDirection = state.sortDirection,
182
- scrollTop = 2000 ,
183
- headerHeight = 30
171
+ disableHeader = false ,
172
+ noRowsRenderer = () => < .div(^ .cls := " noRows" , " No rows" ),
173
+ overscanRowCount = 10 ,
174
+ rowClassName = rowClassName _,
175
+ height = 600 ,
176
+ rowCount = 10 ,
177
+ rowHeight = TableCache .cache.rowHeight.toScala,
178
+ onRowClick = x => Callback .log(x),
179
+ onScroll = (c, s, t) => Callback .log(s " $c $s $t" ),
180
+ width = props.s.width.toInt,
181
+ rowGetter = datum(state.data),
182
+ headerClassName = " headerColumn" ,
183
+ sort = sort _,
184
+ sortBy = props.sortBy,
185
+ sortDirection = state.sortDirection,
186
+ scrollTop = 2000 ,
187
+ headerHeight = 30
184
188
),
185
189
columns : _*
186
190
)
0 commit comments