Nested tables with related parent content - html-table

Having a semantics issue. I have a basic table with a standard header and footer. Each row contains an order, beneath each row I need to display another table, that will contain a break down of costs relating to that order. Additionally, these inner tables will be displayed with a jQuery accordion to hide and show when required (but I'm just concentrating on the HTML for now)
How can I semantically approach this in HTML?
<table>
<thead>
<th>Package number</th>
<th>Date placed</th>
<th>Placed by</th>
<th>Total cost</th>
</thead>
<tr>
<td>1</td>
<td>Weds</td>
<td>Jonno</td>
<td>£15</td>
</tr>
<tr>
<td colspan="4">
<table>
<thead>
<th>Part number</th>
<th>Description</th>
<th>Qty shipped</th>
<th>Weight</th>
</thead>
<tbody>
<td>18293</td>
<td>Blah blah blah</td>
<td>72</td>
<td>20Kg</td>
</tbody>
</table>
</td>
</tr>
<tr>
<td>2</td>
<td>Thurs</td>
<td>Jonno</td>
<td>£1</td>
</tr>
<tr>
<td>3</td>
<td>Fri</td>
<td>Jonno</td>
<td>£7</td>
</tr>
</table>
Here's a fiddle: http://jsfiddle.net/yuW7f/ - The problem here is that the row containing the inner table, is totally unrelated to the order row

If you are looking for a parent element you can use to group related rows, you can use <tbody> elements. A table can have multiple <tbody> elements:
<table>
<thead>
<tr>
<th>Package number</th>
<th>Date placed</th>
<th>Placed by</th>
<th>Total cost</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Weds</td>
<td>Jonno</td>
<td>£15</td>
</tr>
<tr>
<td colspan="4">
<table>
<thead>
<tr>
<th>Part number</th>
<th>Description</th>
<th>Qty shipped</th>
<th>Weight</th>
</tr>
</thead>
<tbody>
<tr>
<td>18293</td>
<td>Blah blah blah</td>
<td>72</td>
<td>20Kg</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
<tr>
<td>2</td>
<td>Thurs</td>
<td>Jonno</td>
<td>£1</td>
</tr>
<tr>
<td>3</td>
<td>Fri</td>
<td>Jonno</td>
<td>£7</td>
</tr>
</table>
Whether or not that makes your code more semantically correct is debatable. You could also give your rows classes to indicate whether the row is a summary row or a detail row, or attributes to indicate relationships to other rows. Semantically, it seems fine as it is to me.
By the way, you are missing some <tr> elements. A <tbody>, <thead>, or <tfoot> element does not replace a <tr> element.

Related

rowSpan hides rows

<table>
<tr> <td rowspan="2">1</td> <td>2</td> </tr>
<tr> <td rowspan="2">3</td> </tr>
<tr> <td>4</td> </tr>
</table>
seemingly only displays two rows:
The reason for hiding the second row [1 3] is, that the cells with text 1 and 3 are reduced in height. Is there a way to ensure, that the second row is visible in the display (not only in DOM)?
The problem gets clearer, if you look at the same table with an additional column:
<table>
<tr> <td rowspan="2">1</td> <td>2</td> <td>0</td> </tr>
<tr> <td rowspan="2">3</td> <td>0</td> </tr>
<tr> <td>4</td> <td>0</td> </tr>
</table>
which is displayed like:
You can add a height property to the row:
<table border=1>
<tr>
<td rowspan="2">1</td>
<td>2</td>
</tr>
<tr style="height: 1.5em">
<td rowspan="2">3</td>
</tr>
<tr>
<td>4</td>
</tr>
</table>
One suboptimal option could be to add an empty column:
<table>
<tr> <td rowspan="2">1</td> <td>2</td> <td class="void"></td> </tr>
<tr> <td rowspan="2">3</td> <td class="void"></td> </tr>
<tr> <td>4</td> <td class="void"></td> </tr>
</table>
CSS:
table,td {border:1px solid}
.void {height:1em;padding:0;border:0}
However, the spacing between columns leads to unnecessary space for the added column:
As this problem could be solved with padding-left for TD and a cellspacing of 0 for the table, this solution would not be general enough, so I'm still waiting for a good idea.

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

want a query for searching that gives the precise output in aspect of group searching?

Hi to all I am stuck in searching and below 3 tables were given i.e Invoice table,service table and tax detail table for your better understanding
I need sql query for searching in below tables If I will pass parameter as taxId of tax detail table and want output as mention below.
Please guys help me out in this and suggest me a single sql query for the same and If I will get the exact query from any person I will endorse his account.
1) Invoice Table
<table border=1>
<tr><td>Invoiceid(PK)</td><td>Client</td><td>Amount</td><td>Tax</td><td>totalamount</td>
</tr>
<tr>
<td>1</td><td>abc</td><td>12500</td>
<td>1000</td><td>13500</td>
</tr>
<tr>
<td>2</td><td>xyz</td><td>6280</td>
<td>1000</td><td>7280</td>
</tr>
<tr>
<td>3</td><td>mno</td><td>10000</td>
<td>1000</td><td>11000</td>
</tr>
<tr>
<td>4</td><td>efg</td><td>5600</td>
<td>400</td><td>6000</td>
</tr>
<tr>
<td>5</td><td>pqr</td><td>5000</td>
<td>1000</td><td>6000</td>
</tr>
<tr>
<td>6</td><td>rst</td><td>3000</td>
<td>0</td><td>3000</td>
</tr>
<tr>
<td>7</td><td>jkl</td><td>3800</td>
<td>1200</td><td>5000</td>
</tr>
</table>
2) Service Table
<table border=1>
<tr><td>Invoiceserviceid(PK)</td><td>Invoiceid(FK)</td>
<td>Serviceid</td><td>Amount</td>
</tr>
<tr>
<td>1</td><td>1</td>
<td>12</td><td>8000</td>
</tr>
<tr>
<td>2</td><td>1</td>
<td>16</td><td>4500</td>
</tr>
<tr>
<td>3</td><td>2</td>
<td>17</td><td>1000</td>
</tr>
<tr>
<td>4</td><td>2</td>
<td>22</td><td>1100</td>
</tr>
<tr>
<td>5</td><td>2</td>
<td>36</td><td>2200</td>
</tr>
<tr>
<td>6</td><td>2</td>
<td>46</td><td>1980</td>
</tr>
<tr>
<td>7</td><td>3</td>
<td>75</td><td>10000</td>
</tr>
<tr>
<td>8</td><td>4</td>
<td>69</td><td>2500</td>
</tr>
<tr>
<td>9</td><td>4</td>
<td>88</td><td>3600</td>
</tr>
<tr>
<td>10</td><td>5</td>
<td>89</td><td>5000</td>
</tr>
<tr>
<td>11</td><td>6</td>
<td>90</td><td>2000</td>
</tr>
<tr>
<td>12</td><td>6</td>
<td>15</td><td>1000</td>
</tr>
<tr>
<td>13</td><td>7</td>
<td>32</td><td>3800</td>
</tr>
</table>
3) TAX Details Table
<table border=1>
<tr><td>taxdetailid(PK)</td><td>Invoiceid(FK)</td>
<td>taxid</td><td>Taxname</td>
<td>taxamount</td>
</tr>
<tr>
<td>1</td><td>1</td><td>1</td>
<td>GST</td><td>1000</td>
</tr>
<tr>
<td>2</td><td>2</td><td>2</td>
<td>CGST</td><td>500</td>
</tr>
<tr>
<td>3</td><td>2</td><td>3</td>
<td>SGST</td><td>500</td>
</tr>
<tr>
<td>4</td><td>3</td><td>1</td>
<td>GST</td><td>500</td>
</tr>
<tr>
<td>5</td><td>3</td><td>2</td>
<td>CGST</td><td>250</td>
</tr>
<tr>
<td>6</td><td>3</td><td>3</td>
<td>SGST</td><td>250</td>
</tr>
<tr>
<td>7</td><td>4</td><td>1</td>
<td>GST</td><td>300</td>
</tr>
<tr>
<td>8</td><td>4</td><td>3</td>
<td>SGST</td><td>100</td>
</tr>
<tr>
<td>9</td><td>5</td><td>2</td>
<td>CGST</td><td>1000</td>
</tr>
<tr>
<td>10</td><td>7</td><td>1</td>
<td>GST</td><td>1200</td>
</tr>
</table>
OUT PUT
Pass Parameter 'Taxid' of tax details table
Pass Parameter value (1)
<table border=1>
<tr><td>Invoiceid</td><td>Client</td><td>Serviceid</td><td>Serviceamount</td>
</tr>
<tr><td>1</td><td>abc</td><td>12</td><td>8000</td>
</tr>
<tr><td>1</td><td>abc</td><td>16</td><td>4500</td>
</tr>
<tr><td>7</td><td>jkl</td><td>32</td><td>3800</td>
</tr>
</table>
Pass Parameter value (2,3)
<table border=1>
<tr><td>Invoiceid</td><td>Client</td><td>Serviceid</td><td>Serviceamount</td>
</tr>
<tr><td>2</td><td>xyz</td><td>17</td><td>1000</td>
</tr>
<tr><td>2</td><td>xyz</td><td>22</td><td>1100</td>
</tr>
<tr><td>2</td><td>xyz</td><td>36</td><td>2200</td>
</tr>
<tr><td>2</td><td>xyz</td><td>46</td><td>1980</td>
</tr>
</table>
Pass Parameter value (NULL)
<table border=1>
<tr><td>Invoiceid</td><td>Client</td><td>Serviceid</td><td>Serviceamount</td>
</tr>
<tr><td>6</td><td>rst</td><td>90</td><td>2000</td>
</tr>
<tr><td>6</td><td>rst</td><td>15</td><td>1000</td>
</tr>
</table>
Also pass
parameter (1,2,3) result invoiceid (3)
parameter (2) result invoiceid (5)
Parameter (1,3) result invoiceid (4)

Move the content, not text, of a table's cell to the right

I have a series of nested tables, below I created a jsfiddle structure.
I was using the arab notation, ( direction: rtl ) which is obviously wrong. I can not find the right css that moves the content to the right.
I wish to recreate the same structure.
Without using direction: rtl; because this makes the text reversed too. Borders are only to highlight it better.
Thanks to anyone who can help me
https://jsfiddle.net/wo77wgL5/
<table width = "800px" border=3 class="centralTable">
<tr>
<th></th>
<th></th>
<th>header 1</th>
<th>header 2</th>
<th>header 3</th>
<th>header 4</th>
</tr>
<tbody>
<tr>
<td> </td>
<td> </td>
<td>Text 1</td>
<td>Text 2</td>
<td>Text 3</td>
<td>Text 4</td>
</tr>
<tr>
<td colspan=6 style= "direction:rtl;">
<table width = "500px" border=1 class="toTheRight">
<tr>
<th></th>
<th></th>
<th>header 11</th>
<th>header 22</th>
<th>header 33</th>
<th>header 44</th>
</tr>
<tbody>
<tr>
<td> </td>
<td> </td>
<td>Text 11</td>
<td>Text 22</td>
<td>Text 33</td>
<td>Text 44</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
You can use <td align="right">
https://jsfiddle.net/msp5m4k9

How to append a string in between a string for multiple records in SQL

trying to update a table which is something like this , the desired output is the second table .... Looking for an update query in SQL that can add a string in between a given string............................................
<table>
<tr>
<!--<td >ID</td>-->
<td>ID</td>
<td>ProductName</td>
</tr>
<tr>
<!--<td rowspan="3">1</td>-->
<td>1</td>
<td>H2413_H1_2013_Lotus</td>
</tr>
<tr>
<td>2</td>
<td>H2413_P1_2013_Lotus</td>
</tr>
<tr>
<td>3</td>
<td>H2413_T1_2013_Lotus</td>
</tr>
<!--<tr><td colspan="3">---------------------</td></tr>-->
<tr>
<!--<td>ID</td>-->
<td>ID</td>
<td>ProductName</td>
</tr>
<tr>
<!--<td rowspan="3">2</td>-->
<td>1</td>
<td>H2413_H1_2013_Det_Lotus</td>
</tr>
<tr>
<td>2</td>
<td>H2413_P1_2013_Det_Lotus</td>
</tr>
<tr>
<td>3</td>
<td>H2413_T1_2013_Det_Lotus</td>
</tr>
</table>
I'm going to make an assumption here that the 2013 value can change in the product name. Take a look at the Replace Command
Using Replace something like this should work
UPDATE
Products
SET
ProductName = REPLACE(ProductName,'2013_Lotus', '2013_DET_Lotus')