<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.7/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="css/styles.css">
    <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.7.0.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.print.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/select/1.7.0/js/dataTables.select.min.js"></script>
    
</head>
<body>
    <div class = wrapper>
        <table id="example" class="display" style="width:100%">
            <thead>
                <tr>
                    <th></th>
                    <th>Last Name(s)</th>
                    <th>First Name(s)</th>
                    <th>Title</th>
                    <th>Media</th>
                    <th>Year</th>
                    <th>Tags</th>
                </tr>
            </thead>
        </table>
    </div>
</body>
</html>
 
@font-face {
  font-family: 'concourse';
  src: url('../fonts/concourse/concourse_2_regular.woff2') format('woff2');
}
body {
  font-family: concourse, Helvetica, sans-serif;
  height: 100vh;
}
/*colour for row hover*/
table#example.dataTable tbody tr:hover {
  background: #BBE5E5;
}
 
table#example.dataTable tbody tr:hover > .sorting_1 {
  background: #BBE5E5;
}
/*colour for selected rows*/
:root {
  --dt-row-selected: 112,132,132;
}
/*colour for row borders when selected (otherwise remain blue)*/
table#example.dataTable tbody tr.selected td {
   border-top: 1px solid rgb(112,132,132);
}
/*icons for detail row expand and collapse*/
table.dataTable td.dt-control:before {
  display: inline-block;
  color: black;
  content: "→";
}
table.dataTable tr.dt-hasChild td.dt-control:before {
  color: black;
  content: "↓";
}
.wrapper{
  height: 100vh;
}
.controls{
  display: flex;
  height: 3em;
  align-content: center;
  padding: 1em;
  border: 1px solid red;
}
.search{
  padding-right: 1em;
  border: 1px solid blue;
}
.export{
  display: flex;
  align-content: center;
  align-items: center;
  border: 2px dashed red;
}
.selection{
   border: 2px solid blue;
}
.buttons{
  border: 2px solid green;
}
.copyButton{
  background-color: green;  
}
 
$(document).ready(function() {
    // function for detail rows
    // d = original data object for the row
    // if there is an entry in notes, description, hyperlink, or contributor, add to the detail row
    function format(d) {
        let info = '';
        if(d.Notes){
            info += '<dt>Notes:</dt>' + d.Notes;
        }
        if(d.Description){
            info += '<dt>Description:</dt>' + d.Description;
        }
        if(d.Hyperlink){
            info += '<dt>Hyperlink:</dt>' + '<a href="' + d.Hyperlink + '" target="_blank">' + d.Hyperlink + '</a>';
        }
        // if(d.Contributor){
        //     info += '<dt>Contributor:</dt>' + d.Contributor;
        // }
        if(info === null){
            var td = $(row).find("td:first");
            td.removeClass( 'dt-control' );
        }else{
            return(info);
        }
        
    }   // format
    // declaration of table using Datatables
    let table = new DataTable('#example', {
        //ajax: 'ajax/data/pg_resources_all_standard.json',
        dom: '<"controls"<"search"f><"export"<"selection"><"buttons"B>>>t',
        fnInitComplete: function(){
           $('div.selection').html('<p>Selection:</p>');
         },
        paging: false,
        scrollCollapse: true,
        scrollY: '100vh',
        buttons: [
            { extend: 'copy', className: 'copyButton' },
            {
            extend: 'pdfHtml5',
            title: 'Selected Titles',
            text: 'PDF',
            orientation: 'landscape',
            pageSize: 'A4',
            exportOptions: {
                columns: [ 0, 1, 2, 3, 4, 5, 6 ]
                },
            }   
        ],
        select: true,
        columns: [
        {
            className: 'dt-control',
            orderable: false,
            data: null,
            defaultContent: ''
        },
        { data: 'Last Name' },
        { data: 'First name' },
        { data: 'Title' },
        { data: 'Media' },
        { data: 'Year' },
        { data: 'Tags' },
        ],
        // check if columns past this contain data, if not remove the details row control arrow (dt-control)
        createdRow: function ( row, data, index ) {
            let details_row_data = data.Notes + data.Description + data.Hyperlink;
            if (!details_row_data) {
              var td = $(row).find("td:first");
              td.removeClass( 'dt-control' );
            }
           },
        order: [[1, 'asc']],
    }); // table declaration
    // event listener for opening and closing detail rows
    
    table.on('click', 'td.dt-control', function (e) {
        let tr = e.target.closest('tr');
        let row = table.row(tr);
        // if row is open then close it, else open details row
        if (row.child.isShown()) {
            row.child.hide();
        }
        else {
            row.child(format(row.data())).show();
        }
    });
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers