@@ -8,6 +8,7 @@ export interface DataFrameWidgetProps {
88 index: any [];
99 columns: any [];
1010 data: any [][];
11+ indexNames: any [];
1112}
1213const props = defineProps <DataFrameWidgetProps >();
1314
@@ -61,6 +62,14 @@ const visibleRows = computed(() => {
6162 return rows .value .slice (pageStart .value , pageEnd .value );
6263});
6364
65+ const indexNamesColSpan = computed (() => {
66+ const hasIndexNames = props .indexNames .some ((name ) => name !== null );
67+ if (hasIndexNames ) {
68+ return props .indexNames .length ;
69+ }
70+ return 1 ;
71+ });
72+
6473function nextPage() {
6574 if (currentPage .value < totalPages .value - 1 ) {
6675 currentPage .value ++ ;
@@ -90,13 +99,31 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
9099 <table >
91100 <thead >
92101 <tr >
93- <th >index</th >
102+ <th :colspan = " indexNamesColSpan " >index</th >
94103 <th v-for =" (name, i) in props.columns" :key =" i" >{{ name }}</th >
95104 </tr >
105+ <tr v-if =" indexNamesColSpan > 1" >
106+ <th v-for =" (name, i) in props.indexNames" :key =" i" class =" named-index" >
107+ {{ name }}
108+ </th >
109+ <th v-for =" (name, i) in props.columns" :key =" i" ></th >
110+ </tr >
96111 </thead >
97112 <tbody >
98113 <tr v-for =" (row, i) in visibleRows" :key =" i" >
99- <td v-for =" (value, i) in row" :key =" i" >{{ value }}</td >
114+ <template v-if =" indexNamesColSpan === 1 " >
115+ <td v-for =" (value, i) in row" :key =" i" :colspan =" i === 0 ? indexNamesColSpan : 1" >
116+ {{ value }}
117+ </td >
118+ </template >
119+ <template v-else >
120+ <td v-for =" (value, i) in row[0].split(', ')" :key =" i" class =" named-index" >
121+ {{ value }}
122+ </td >
123+ <td v-for =" (value, i) in row.slice(1)" :key =" i" >
124+ {{ value }}
125+ </td >
126+ </template >
100127 </tr >
101128 </tbody >
102129 </table >
@@ -155,19 +182,24 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
155182 & tr {
156183 & th {
157184 padding : var (--spacing-padding-small );
185+ text-align : right ;
158186
159- &:first-child {
187+ &:first-child,
188+ &.named-index {
189+ background-color: var (--background-color-elevated );
190+ }
191+
192+ &[colspan = " 1" ]:first-child:not (.named-index ) {
160193 position : sticky ;
161194 left : 0 ;
162- background-color : var (--background-color-elevated );
163- text-align : left ;
164195 }
165196 }
166197 }
167198 }
168199
169200 & tbody {
170201 & tr {
202+ position : relative ;
171203 padding : var (--spacing-padding-small );
172204
173205 & td {
@@ -176,16 +208,18 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
176208 font-size : var (--text-size-highlight );
177209 font-weight : var (--text-weight-highlight );
178210
179- &:first-child {
180- position: sticky ;
181- left : 0 ;
182- width : auto ;
211+ &:first-child,
212+ &.named-index {
183213 background-color: var (--background-color-elevated );
184214 color : var (--text-color-normal );
185215 font-size : var (--text-size-normal );
186216 font-weight : var (--text-weight-normal );
187217 text-align : left ;
188- white-space : nowrap ;
218+ }
219+
220+ &:first-child:not (.named-index ) {
221+ position : sticky ;
222+ left : 0 ;
189223 }
190224 }
191225
@@ -195,6 +229,7 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
195229 }
196230 }
197231
232+ /* stylelint-disable no-descending-specificity */
198233 & > thead > tr :not (:last-child ) > th ,
199234 & > thead > tr :not (:last-child ) > td ,
200235 & > tbody > tr :not (:last-child ) > th ,
0 commit comments