overlapped column header text in Datatable - datatables

I use datatable for displaying data and table has 14 columns
but i facing issue in display table header data.It overlapped rather then display in two lines
I create table like this
<table id="tbl" class="table" cellspacing="0" width="100%" style="word-wrap:break-word;
table-layout: fixed;">
<thead>
<tr>
<th>Column Name</th>
</tr>
</thead>
</table>
How can i do it in two lines

<table id="tbl" class="table" cellspacing="0" width="100%" style="word-wrap:break-word;
table-layout: fixed;">
<thead>
<tr>
<th style="word-wrap: break-word;">Column Name</th>
</tr>
</thead>
</table>
overfow:hidden should do the trick ;-)

Related

Is <tbody> automatically defined in a table?

I'm a starter and I was trying some elements, as practice.
There's sth that i can't figure it out.I also have searched google but no answers found.
I wrote 2 tables, in the first one I used tbody to style the body of the table. But when I load the page, I see the style used in css for the tbody in the first table, has also effected the second table(without tbody tag) completely.Why is this happening?
Here is the code :
<table id="t1">
<caption>UFO Seen by People</caption>
<thead>
<tr>
<th>Name</th>
<th>City Name</th>
<th>Seen</th>
<th>Times seen</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3">Jack</td>
<td>North Russia</td>
<td>2020-06-12</td>
<td>once</td>
</tr>
<tr>
<td>North Korea</td>
<td>2000-06-12</td>
<td>once</td>
</tr>
<tr>
<td>North Pole</td>
<td>1995-06-12</td>
<td>twice</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">Blah Blah Blah</td>
</tr>
</tfoot>
</table>
<table id="t2">
<caption>UFO Seen by People2</caption>
<colgroup>
<col span="2" style="text-align:right; background-color:yellow;">
<col style="background-color:cyan; background-image:url('baelen.jpg');">
</colgroup>
<tr>
<th>Name</th>
<th>City Name</th>
<th>Seen</th>
<th>Times seen</th>
</tr>
<tr>
<td rowspan="3">Dan</td>
<td>North Russia</td>
<td>2020-06-12</td>
<td>once</td>
</tr>
<tr>
<td>North Korea</td>
<td>2000-06-12</td>
<td>once</td>
</tr>
<tr>
<td>North Pole</td>
<td>1995-06-12</td>
<td>twice</td>
</tr>
</table>
And here is the css used :
#t1 { border:2px solid black; border-spacing:10pt; background-color:pink; width:100%;}
#t2 { border:2px solid rgb(20,20,20); border-collapse:collapse; width:100%;}
tbody { background-color:white; text-align:center; vertical-align:middle; font-size:20pt;}
That's really simple, that affect the second table cause you use tbody in css and not #t1 tbody, use correct selector if you want to affect only one element.
In addition I advise you not to use style on HTML and in CSS except in the case of manipulation in JavaScript. This will also allow you to better understand what does what, if you want to give a particular style to elements of your table assign their classes to your CSS.

Simple table with colspan giving errors with datatables

I have this simple html table
<table id="mytable">
<thead>
<tr>
<th>Name</th>
<th colspan="2">Actions</th>
</tr>
<tr>
<th>Delete</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<tr>
<td>MyName</td>
<td onclick="delete()">X</td>
<td onclick="update()">U</td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function(){
$('#mytable').DataTable();
});
</script>
If i open this on the browser i get
"Cannot read property 'mData' of undefined".
I don't undestand where is the problem.. I am following the official example: https://datatables.net/examples/basic_init/complex_header.html
Thank you all!
your html have unmatched number of columns, notice the first row of your header has colspan while the second row doesn't.
what you can do is to provide a rowspan.
<thead>
<tr>
<th rowspan="2">Name</th>
<th colspan="2">Actions</th>
</tr>
<tr>
<th>Delete</th>
<th>Update</th>
</tr>
</thead>
here's a link to the datatables example of complex headers. https://datatables.net/examples/basic_init/complex_header.html

Multiple jquery datatables on same page causing width issue. (Datatables v10.13)

It causes width issue for both tables. Refer the code below,
<table id="tblMessages" class="table table-striped table-bordered full-width table-advance table-hover table-condensed fl" style="border-collapse:collapse !important;">
<thead>
<tr>
<th style="cursor:pointer; width:20%">From</th>
<th style="cursor:pointer; width:60%">Subject</th>
<th style="cursor:pointer; width:20%">Date</th>
</tr>
</thead>
<tbody></tbody>
</table>
And here is second table,
<table id="tblToDos" class="table table-striped table-bordered table-advance full_width table-hover table-condensed fl" style="border-collapse:collapse !important">
<thead>
<tr>
<th style="width:5%"></th>
<th style="cursor:pointer; width:20%">From</th>
<th style="cursor:pointer; width:30%">Patient</th>
<th style="cursor:pointer; width:35%">Subject</th>
<th style="cursor:pointer; width:10%">Reminder Date</th>
</tr>
</thead>
Note that I tried with giving width in "Columns" property of Datatables but no luck.
And if I removed second table init then it is working fine.
I got the solution. Though it is not a proper solution but we can solve this matter by redraw the grid using below code.
$('#tblMessages').DataTable().columns.adjust().draw();
Put this line after you are done with initialising second datatable.

<td style='text-align: right'> incorrectly aligned in IE11

I am trying to right align the values, but those are not aligning properly to the end of the column.
Example code:
<table id="demoTable1" cellspacing="0" cellpadding="0" border="1">
<thead>
<tr>
<th style="text-align:right; width:23%"><bean:message key="label.amount"/></th>
</tr>
</thead>
<tbody >
<c:forEach items="${demoForm.amount}" var="amt" >
<tr>
<td dntitle="myAmt" style="text-align:right; width:23%">
<util:myCurrency name="amt" property="amtList" currProperty="curCode"/>
</td>
</tr>
</c:forEach>
</tbody>
</table>
And the Output looks like this:
How can I fix this?

Table Headers in PDF module in Play Framework

I'm using play framework. I am able to generate the PDF using PDF module. My Problem here is i want to add the table headers in every page. Here is my code
<table width="100%" border="1" id="example" cellspacing="0" cellpadding="0" style="border-collapse: collapse" class="-fs-table-paginate: paginate;">
<thead>
<tr>
<th align="center"><b>Items</b></th>
<th align="center"><b>Quantity</b></th>
<th align="center"><b>Unit Price</b></th>
<th align="center"><b>Amount(Rs).</b></th>
</tr>
</thead>
.....
</table>
I saw here. i added -fs-table-paginate: paginate; in the class attibute. But the table headers are not continued in the next page.
I don't know how to use this. Can you help me Pl.
EDIT: can anyont help me please....
You should add "-fs-table-paginate: paginate;" to the style attribute, not to the class attribute:
<table width="100%" border="1" id="example" cellspacing="0" cellpadding="0" style="border-collapse: collapse; -fs-table-paginate: paginate;">