How to simply add a "title" to a table?

How to simply add a "title" to a table?

erwin007erwin007 Posts: 3Questions: 1Answers: 0

I need to add a title to the table and can't find anywhere an easy solution.

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    There is nothing built into Datatables for this. You can add the appropriate HTML above the table tag in you document. If you want the title integrated with the Datatables elements you can use the technique in this example.

    Kevin

  • erwin007erwin007 Posts: 3Questions: 1Answers: 0

    Hi Kevin, this is already a great help but when I actually want to print the table (=save as pdf) that title isn't there.
    This is my code:







    <script>
        $(document).ready( function () {
            $('#myTable').dataTable({
                "ordering": false
            })
    
        $('#myTable2').dataTable({
            "ordering": false,
            dom: 'Bf<"toolbar">tip',
            "buttons": ['print']
    
            });
    
        $('div.toolbar').html('<b>This should work!</b>');  
    
    
        });
    </script>
    
  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    See this example which shows adding a title to the export.

    Kevin

  • erwin007erwin007 Posts: 3Questions: 1Answers: 0

    Kevin, you are my hero for today!! :)
    Thank you so much!

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    The other option, is to use the caption tag for tables. It has the advantage of being the semantic tag for exactly the method you describe, so screen readers, etc will handle it correctly (or at least should!).

    Here is a little example of that.

    Allan

Sign In or Register to comment.