@@ -431,6 +431,8 @@ def _more_tabcol(tabcol, max_lines=None, max_width=None, show_name=True,
431431
432432
433433def _jsviewer (display_length = 50 ,
434+ ipynb = False ,
435+ tableid = None ,
434436 css_urls = ("http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ,
435437 "http://jquery-datatables-editable.googlecode.com/svn/trunk/media/css/demo_page.css" ,
436438 "http://jquery-datatables-column-filter.googlecode.com/svn/trunk/media/css/demo_table.css" )):
@@ -440,20 +442,53 @@ def _jsviewer(display_length=50,
440442 for L in display_length_menu :
441443 if display_length not in L :
442444 L .insert (0 ,display_length )
443- js = (['<link rel="stylesheet" href="{css}" type="text/css">' .format (css = css ) for css in css_urls ] +
444- ['<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>' ,
445- '<script class="jsbin" src="http://datatables.net/download/build/jquery.dataTables.nightly.js"></script>' ,
446- '''<script>
447- $(document).ready(function() {{
448- $('#table').dataTable({{
449- "iDisplayLength": {display_length},
450- "aLengthMenu": {display_length_menu},
451- "bJQueryUI": true,
452- "sPaginationType": "full_numbers"
453- }});
454- }} );
455- </script>''' .format (display_length = display_length ,
456- display_length_menu = display_length_menu )
457- ])
445+ js = ['<link rel="stylesheet" href="{css}" type="text/css">' .format (css = css ) for css in css_urls ]
446+ if ipynb :
447+ js += ['<script class="jsbin" src="http://datatables.net/download/build/jquery.dataTables.nightly.js"></script>' ,
448+ '''<script>
449+ function html_repr_full() {{
450+ var kernel = IPython.notebook.kernel;
451+ var button = $("#MakeTableBrowseable{tid}");
452+ var tablename = button.parents()[4].getElementsByClassName("input_area")[0].innerText;
453+ var command = tablename + ".pformat(html=True, max_lines=1000, max_width=1000)";
454+ var result = kernel.execute(command, {{'output': callback}}, {{silent:true}});
455+ }};
456+ function callback(output_type, out) {{
457+ var button = $("#MakeTableBrowseable{tid}");
458+ button[0].parentNode.innerHTML = out.data;
459+ }};
460+ function make_table() {{
461+ $('#table').dataTable({{
462+ "iDisplayLength": {display_length},
463+ "aLengthMenu": {display_length_menu},
464+ "bJQueryUI": true,
465+ "sPaginationType": "full_numbers"
466+ }});
467+ }};
468+ function replace_table() {{
469+ html_repr_full();
470+ make_table();
471+ }};
472+ </script>
473+ <button id='MakeTableBrowseable{tid}' onclick="replace_table()">Make Table Browseable</button>
474+ ''' .format (display_length = display_length ,
475+ display_length_menu = display_length_menu ,
476+ tid = tableid )
477+ ]
478+ else :
479+ js += ['<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>' ]
480+ js += ['<script class="jsbin" src="http://datatables.net/download/build/jquery.dataTables.nightly.js"></script>' ,
481+ '''<script>
482+ $(document).ready(function() {{
483+ $('#table').dataTable({{
484+ "iDisplayLength": {display_length},
485+ "aLengthMenu": {display_length_menu},
486+ "bJQueryUI": true,
487+ "sPaginationType": "full_numbers"
488+ }});
489+ }} );
490+ </script>''' .format (display_length = display_length ,
491+ display_length_menu = display_length_menu )
492+ ]
458493
459494 return js
0 commit comments