@@ -220,16 +220,21 @@ def to_html_datatable(df=None, caption=None, tableId=None, connected=True, **kwa
220220 ):
221221 kwargs [option ] = getattr (opt , option )
222222
223+ for name , value in kwargs .items ():
224+ if value is None :
225+ raise ValueError (
226+ "Please don't pass an option with a value equal to None ('{}=None')" .format (
227+ name
228+ )
229+ )
230+
223231 # These options are used here, not in DataTable
224232 classes = kwargs .pop ("classes" )
225233 style = kwargs .pop ("style" )
226234 css = kwargs .pop ("css" )
227235 tags = kwargs .pop ("tags" )
228236
229- # Only display the table if the rows fit on one 'page'
230- if "dom" not in kwargs and len (df ) <= 10 : # the default page has 10 rows
231- if "lengthMenu" not in kwargs or len (df ) <= min (kwargs ["lengthMenu" ]):
232- kwargs ["dom" ] = "t"
237+ _set_dom_equals_t_if_df_fits_in_one_page (df , kwargs )
233238
234239 if caption is not None :
235240 tags = '{}<caption style="white-space: nowrap; overflow: hidden">{}</caption>' .format (
@@ -275,10 +280,6 @@ def to_html_datatable(df=None, caption=None, tableId=None, connected=True, **kwa
275280 "'header', 'footer' or False, not {}" .format (column_filters )
276281 )
277282
278- # Do not show the page menu when the table has fewer rows than min length menu
279- if "paging" not in kwargs and len (df .index ) <= kwargs .get ("lengthMenu" , [10 ])[0 ]:
280- kwargs ["paging" ] = False
281-
282283 # Load the HTML template
283284 if connected :
284285 output = read_package_file ("html/datatables_template_connected.html" )
@@ -362,6 +363,29 @@ def _column_count_in_header(table_header):
362363 return max (line .count ("</th>" ) for line in table_header .split ("</tr>" ))
363364
364365
366+ def _min_rows (kwargs ):
367+ if "lengthMenu" not in kwargs :
368+ return 10
369+
370+ lengthMenu = kwargs ["lengthMenu" ]
371+ min_rows = lengthMenu [0 ]
372+
373+ if isinstance (min_rows , (int , float )):
374+ return min_rows
375+
376+ return min_rows [0 ]
377+
378+
379+ def _set_dom_equals_t_if_df_fits_in_one_page (df , kwargs ):
380+ """Display just the table (not the search box, etc...) if the rows fit on one 'page'"""
381+ if "dom" in kwargs :
382+ return
383+
384+ if len (df ) <= _min_rows (kwargs ):
385+ kwargs ["dom" ] = "t"
386+ return
387+
388+
365389def safe_reset_index (df ):
366390 try :
367391 return df .reset_index ()
0 commit comments