Loading...
S2 can manually drag and drop to dynamically change the width and height of cells. At the same time, there are three built-in layouts: row and column行列等宽
,列等宽
and行列紧凑布局
layout ( see examples )
We can modify the background color, font size and other configurations of the cell through the theme . If you want to customize the width and height of the cell, you can use the style configuration of s2Options
to achieve it
const s2Options = {style: {// 行头单元格配置rowCell: {},// 列头单元格配置colCell: {},// 数值单元格配置dataCell: {},},}
Priority is less than
rowCell.height
andcolCell.width
const s2Options = {style: {dataCell: {width: 100,height: 90},},}
The height of row header cell and the width of column header cell are always consistent with the value cell, so it is equivalent to adjusting the height of row header and the width of column header at this time.
The height adjustment of row header cells is applied to leaf nodes (the height of non-leaf nodes is the sum of the heights of all child nodes), and the height is always consistent with the height of the value cell .
const s2Options = {style: {rowCell: {width: 50,height: 50},},}
It can also be dynamically adjusted according to the current row header node information, returning null
means using the default width and height
const s2Options = {style: {rowCell: {width: (rowNode) => {// 例:叶子节点 300px, 非叶子节点 200pxreturn rowNode.isLeaf ? 300 : 200;},height: (rowNode) => {// 例:偶数行高度 300pox, 奇数行默认高度return rowNode.level % 2 === 0 ? 300 : null,}},},}
If you want to set different widths and heights for a specific row/column, you can use rowCell
's widthByField
and heightByField
preset heights to achieve it. Two types of configurations are supported:
root[&] 浙江省[&] 杭州市
): the unique ID corresponding to each row head node after the row and column cross, applicable to specific cells whose width and height are accurate (how to get the ID)city
): corresponds to the field
configured in s2DataConfig.fields.rows
, applicable to cells accurate to a certain type of dimension valueconst s2Options = {style: {rowCell: {widthByField: {city: 100},heightByField: {'root[&] 浙江省 [&] 杭州市': 60,'root[&] 浙江省 [&] 宁波市': 100,},},},}
The schedule is a bit special. Since there are only column headers, if you want to set a different height for a specific row, you can adjust it according to the row number
const s2Options = {style: {rowCell: {// 给第一行和第三行设置不同的高度heightByField: {'1': 130,'3': 60,},},},}
No difference from tile mode configuration
const s2Options = {hierarchyType: 'tree',style: {rowCell: {width: 200,}},}
The width adjustment of column header cells is applied to leaf nodes (the width of non-leaf nodes is the sum of the widths of all child nodes), and the width is always consistent with the width of the value cell
const s2Options = {style: {colCell: {width: 200,height: 60,},},}
If you want to set a different width and height for each column, you can dynamically adjust the width and height according to the current column header node information, return null
to use the default width and height
const s2Options = {style: {colCell: {width: (colNode) => {// 例:前两列宽度 100px, 其他 50pxreturn colNode.colIndex <= 2 ? 100 : 50},height: (colNode) => {// 例:前两列高度 100px, 其他 50pxreturn colNode.colIndex <= 2 ? 100 : 50},},},}
If you want to set different widths and heights for a specific column, you can use colCell
's widthByField
and heightByField
preset widths and heights to achieve it. Two types of configurations are supported:
root[&] 家具[&] 沙发[&]number
): the unique ID corresponding to each column head node after the row and column cross, applicable to specific cells whose width and height are accurate (how to get the ID)city
): corresponds to the field
configured in s2DataConfig.fields.columns
, applicable to cells accurate to a certain type of dimension valueimport { EXTRA_FIELD } from '@antv/s2'const s2Options = {style: {colCell: {widthByField: {// 默认 [数值挂列头], EXTRA_FIELD 为内部虚拟数值列[EXTRA_FIELD]: 60,'root[&] 家具 [&] 沙发 [&]number': 120,},heightByField: {[EXTRA_FIELD]: 80,},},},}
You can also set the height to 0
to achieve the effect of hiding the column header , see an example
const s2Options = {style: {colCell: {height: 0,},},}
object is required , default: null Function description: style setting
parameter | type | required | Defaults | Functional description |
---|---|---|---|---|
layoutWidthType | adaptive | colAdaptive | compact | Cell Width Layout Typeadaptive : Rows and columns are equal in width, equally dividing the entire Canvas canvas widthcolAdaptive : Equal width of columns, compact layout of line headers, the remaining width of the column equally divided canvas width minus the width of line headerscompact : compact row and column layout, when the indicator dimension is small, it cannot cover the entire canvas | ||
dataCell | DataCell | Value cell configuration | ||
colCell | ColCell | Column header cell configuration | ||
rowCell | RowCell | Row header cell configuration |
object is required , default: null Function description: Numerical cell configuration
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
width | cell width | number | 96 | - |
height | cell height | number | 30 | - |
valuesCfg | cell configuration | { originalValueField?: string, widthPercent?: number[], showOriginalValue?: boolean } | - |
object is required , default: null Function description: Column header cell configuration
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
width | Cell width, which can be dynamically set according to the current column header node (leaf nodes are valid) | number | (colNode: Node) => number | 96 | |
height | Cell height, which can be dynamically set according to the current column header node (leaf nodes are valid) | number | (colNode: Node) => number | 30 | |
widthByField | Set the width according to the measurement value (drag or preset width scene), field corresponds to the field or column header id in s2DataConfig.fields.columns , see details | Record<string, number> | - | |
heightByField | Set the height according to the measurement value (drag or preset height scene), the field corresponds to the field or column header id in s2DataConfig.fields.columns , see details | Record<string, number> | - | |
hideValue | The default value hangs the column header, which will display the column header and the value at the same time, and hide the value to make it more beautiful. (that is, s2DataConfig.fields.values and it is only valid for a single value, and it is recommended to use hidden column headers for multiple values) | boolean | false |
object is required , default: null Function description: row header cell configuration
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
width | The row cell width can be dynamically set according to the current row header node, and the tree structure is also applicable | number | (rowNode: Node) => number | Tiles: 96 , Trees: 120 | |
height | Row cell height, which can be dynamically set according to the current row header node | number | (rowNode: Node) => number | 30 | |
collapseFields | Custom folded nodes for row headers in tree mode. Supports two formats: id ( 'root[&] 行头维度值' ) and dimension field ( 'city' ). The priority is higher than collapseAll and expandDepth , and the priority is the lowest when it is set to null . view demo | Record<string, boolean> | ||
collapseAll | Whether to collapse all line headers by default in tree structure mode. | boolean | false | |
expandDepth | In the tree structure mode, the row header expands the expanded level by default (the level starts from 0), and when it is set to null , the priority is the lowest | number | ||
showTreeLeafNodeAlignDot | In the tree mode, whether the row header leaf nodes display the hierarchical placeholders | boolean | false | |
withByField | Set the width of each line according to field . field corresponds to the field or column header id in s2DataConfig.fields.rows , see details | Record<string, number> | - | |
heightByField | Set the height of each row according to field .1. Pivot table: field corresponds to field or column header id in s2DataConfig.fields.rows .2. Detailed table: field corresponds to the row number, starting from 1 . check the details | Record<string, number> | - |