@@ -64,6 +64,11 @@ class Styler(object):
64
64
a unique identifier to avoid CSS collisions; generated automatically
65
65
caption: str, default None
66
66
caption to attach to the table
67
+ cell_ids: bool, default True
68
+ If True, each cell will have an ``id`` attribute in their HTML tag.
69
+ The ``id`` takes the form ``T_<uuid>_row<num_row>_col<num_col>``
70
+ where ``<uuid>`` is the unique identifier, ``<num_row>`` is the row
71
+ number and ``<num_col>`` is the column number.
67
72
68
73
Attributes
69
74
----------
@@ -112,7 +117,7 @@ class Styler(object):
112
117
template = env .get_template ("html.tpl" )
113
118
114
119
def __init__ (self , data , precision = None , table_styles = None , uuid = None ,
115
- caption = None , table_attributes = None ):
120
+ caption = None , table_attributes = None , cell_ids = True ):
116
121
self .ctx = defaultdict (list )
117
122
self ._todo = []
118
123
@@ -136,6 +141,7 @@ def __init__(self, data, precision=None, table_styles=None, uuid=None,
136
141
self .table_attributes = table_attributes
137
142
self .hidden_index = False
138
143
self .hidden_columns = []
144
+ self .cell_ids = cell_ids
139
145
140
146
# display_funcs maps (row, col) -> formatting function
141
147
@@ -306,14 +312,16 @@ def format_attr(pair):
306
312
cs .extend (cell_context .get ("data" , {}).get (r , {}).get (c , []))
307
313
formatter = self ._display_funcs [(r , c )]
308
314
value = self .data .iloc [r , c ]
309
- row_es .append ({
310
- "type" : "td" ,
311
- "value" : value ,
312
- "class" : " " .join (cs ),
313
- "id" : "_" .join (cs [1 :]),
314
- "display_value" : formatter (value ),
315
- "is_visible" : (c not in hidden_columns )
316
- })
315
+ row_dict = {"type" : "td" ,
316
+ "value" : value ,
317
+ "class" : " " .join (cs ),
318
+ "display_value" : formatter (value ),
319
+ "is_visible" : (c not in hidden_columns )}
320
+ # only add an id if the cell has a style
321
+ if (self .cell_ids or
322
+ not (len (ctx [r , c ]) == 1 and ctx [r , c ][0 ] == '' )):
323
+ row_dict ["id" ] = "_" .join (cs [1 :])
324
+ row_es .append (row_dict )
317
325
props = []
318
326
for x in ctx [r , c ]:
319
327
# have to handle empty styles like ['']
0 commit comments