Table columns changing size when hiding/showing row - html

Sorry for the title, I don't really know how to better phrase my question, but here is a more detailed description:
I have a table that has a bunch of rows that is used to keep track of tasks in a todo list sense, and the rows themselves can be clicked on to show a table embedded within one of their columns to keep track of sub-tasks. When I click on one of the tasks to show the subtasks, the width of the column changes. I have the following demonstration:
If you look closely at the first row and the table header, the colum width is changing. I checked this with inspector and it appears for "test shift input" it changes only 1px, whereas for "test shift input and button" the change is more drastic.
The relevant demo is here. And the code will be posted below. I want to know:
Why this happens - I suspect it is width related from the subtasks table? But please correct me if I'm mistaken.
How to fix this, keeping as much of the current structure as possible. I could probably rewrite the whole thing using divs instead of table but it would be nice to not have to do that.
Thanks in advance.
The HTML:
<div>
<table class="table">
<thead>
<tr>
<th><i class="glyphicon glyphicon-check"></i></th>
<th>Task</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td width="10%">
<input type="checkbox" ng-model="item.checked" class="ng-pristine ng-untouched ng-valid">
</td>
<td width="90%">
<input class="form-control ng-pristine ng-untouched ng-valid" ng-model="item.name">
</td>
<td>
<button class="btn btn-primary btn-responsive" ng-click="addItem()"><i class="glyphicon glyphicon-plus"></i></button>
</td>
</tr>
<tr>
<td colspan="3" style="padding:0">
<div class="dataTableContainer" style="height:460px;overflow:auto">
<table class="table">
<tbody>
<tr ng-repeat="thisTodo in todoList track by $index" class="ng-scope">
<td width="10%">
<input type="checkbox" ng-model="thisTodo.checked" ng-click="checked(thisTodo._id,thisTodo.checked)" class="ng-pristine ng-untouched ng-valid">
</td>
<td width="90%">
<div for="0" class="checked-false" onclick="$('#test1').toggle()">
Test shift input and button
</div>
<table id="test1" class="table">
<thead>
<tr>
<th width="10%"><i class="glyphicon glyphicon-check"></i></th>
<th>Subtask</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>
<input type="checkbox" ng-model="thisTodo.subItem.checked" class="ng-pristine ng-untouched ng-valid">
</td>
<td>
<input class="form-control ng-valid ng-dirty ng-touched" ng-model="thisTodo.subItem.name">
</td>
<td>
<button class="btn btn-primary btn-responsive" ng-click="addSubItem(thisTodo)"><i class="glyphicon glyphicon-plus"></i></button>
</td>
</tr>
<!-- ngRepeat: subtask in thisTodo.subtasks --><tr ng-repeat="subtask in thisTodo.subtasks" class="ng-scope">
<td>
<input type="checkbox" ng-model="subtask.checked" ng-click="checkedSubtask(thisTodo._id,subtask._id,subtask.checked)" class="ng-pristine ng-untouched ng-valid">
</td>
<td>
<div class="checked-false">
Test
</div>
</td>
<td>
<button class="btn btn-danger btn-responsive" ng-click="removeSubItem(thisTodo._id,subtask._id)"><i class="glyphicon glyphicon-trash"></i></button>
</td>
</tr><!-- end ngRepeat: subtask in thisTodo.subtasks --><tr ng-repeat="subtask in thisTodo.subtasks" class="ng-scope">
<td>
<input type="checkbox" ng-model="subtask.checked" ng-click="checkedSubtask(thisTodo._id,subtask._id,subtask.checked)" class="ng-pristine ng-untouched ng-valid">
</td>
<td>
<div class="checked-false">
loalsdfjalskdjfalkjfaasdf
</div>
</td>
<td>
<button class="btn btn-danger btn-responsive" ng-click="removeSubItem(thisTodo._id,subtask._id)"><i class="glyphicon glyphicon-trash"></i></button>
</td>
</tr><!-- end ngRepeat: subtask in thisTodo.subtasks -->
</tbody></table>
</td>
<td>
<button class="btn btn-danger btn-responsive" ng-click="remove(thisTodo._id)"><i class="glyphicon glyphicon-trash"></i></button>
</td>
</tr><tr ng-repeat="thisTodo in todoList track by $index" class="ng-scope">
<td width="10%">
<input type="checkbox" ng-model="thisTodo.checked" ng-click="checked(thisTodo._id,thisTodo.checked)" class="ng-pristine ng-untouched ng-valid">
</td>
<td width="90%">
<div for="1" class="checked-false" onclick="$('#test2').toggle()">
Test shift input
</div>
<table id="test2" class="table">
<thead>
<tr>
<th width="10%"><i class="glyphicon glyphicon-check"></i></th>
<th>Subtask</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>
<input type="checkbox" ng-model="thisTodo.subItem.checked" class="ng-pristine ng-untouched ng-valid">
</td>
<td>
<input class="form-control ng-pristine ng-valid ng-touched" ng-model="thisTodo.subItem.name">
</td>
<td>
<button class="btn btn-primary btn-responsive" ng-click="addSubItem(thisTodo)"><i class="glyphicon glyphicon-plus"></i></button>
</td>
</tr>
<!-- ngRepeat: subtask in thisTodo.subtasks -->
</tbody></table>
</td>
<td>
<button class="btn btn-danger btn-responsive" ng-click="remove(thisTodo._id)"><i class="glyphicon glyphicon-trash"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
The CSS:
.table{
width:100%;
table-layout: inherit;
}
.checked-false {
color: black;
background-color: rgba(255, 255, 0, 0.25);
border-radius: 10px;
margin: 5px
}
#test1, #test2 {
display:none;
}

I guess its problem with your td %
You have mentioned table 100% out of that 1st td is 10% and second td is of 90% now what about third td % it will be extra right?
So check your td % and try to match with total %.
I distribute 100% in 10% + 80% + 10%
<tr>
<td width="10%">
<input type="checkbox" ng-model="item.checked" class="ng-pristine ng-untouched ng-valid">
</td>
<td width="80%">
<input class="form-control ng-pristine ng-untouched ng-valid" ng-model="item.name">
</td>
<td>
<button class="btn btn-primary btn-responsive" ng-click="addItem()"><i class="glyphicon glyphicon-plus"></i></button>
</td>
</tr>
here is an updated sample.
https://jsfiddle.net/ccrwj998/1/

You just need to reduce the width of the 2nd <td> element with 90% width and assign width to the 3rd <td element> so that the total width of the three <td> elements sum up to 100%;
Here is the updated fiddle. I have set the width here to 5% for the 3rd <td> element, but you should set it equal to the width of the button.
<tr>
<td width="10%">
<input type="checkbox" ng-model="item.checked" class="ng-pristine ng-untouched ng-valid">
</td>
<td width="85%">
<input class="form-control ng-pristine ng-untouched ng-valid" ng-model="item.name">
</td>
<td width="5%">
<button class="btn btn-primary btn-responsive" ng-click="addItem()"><i class="glyphicon glyphicon-plus"></i></button>
</td>
</tr>

Related

Put a table in a canvas in html

I want to put a canvas over table, but it is not working.
Here is the code:
<canvas>
<table id="gameField" class="gameFieldAll">
<tr>
<td><input class="Field" type="button" id="00K"onclick="g.pressField(0,0)" ></input> </td>
<td class="fieldRL"><input class="Field" type="button" id="01K"onclick="g.pressField(0,1)"></input> </td>
<td><input class="Field" type="button" id="02K"onclick="g.pressField(0,2)"></input> </td>
</tr>
<tr>
<td class="fieldTop"><input class="Field" type="button" id="10K"onclick="g.pressField(1,0)"></input> </td>
<td class="fieldTop fieldRL"><input class="Field" type="button" id="11K"onclick="g.pressField(1,1)"></input> </td>
<td class="fieldTop"><input class="Field" type="button" id="12K"onclick="g.pressField(1,2)"></input> </td>
</tr>
<tr>
<td class="fieldTop"><input class="Field" type="button" id="20K"onclick="g.pressField(2,0)"></input> </td>
<td class="fieldTop fieldRL" ><input class="Field" type="button" id="21K"onclick="g.pressField(2,1)"></input> </td>
<td class="fieldTop"><input class="Field" type="button" id="22K"onclick="g.pressField(2,2)"></input> </td>
</tr>
The table disappears on the webpage.
Any suggestions? Thanks
The solutution is to place the canvas above the table and make the css propertys position „absolute“ and the z-index of the canvas higher than the zindex of the table.

Adding div in table

I'm looking to add some kind of separator within a table so I can apply a styling to a specific portion of the table. The table it divided into six columns which are two sets of the subject, the input box, and the marker.
When I add tags, they're thrown to the top when the html is rendered (inspect element on the jsfiddle). Can I add some kind of separator (div, span, or something else) such that each set of three has only one subject, one input box, and one marker.
I need this because when I add a check mark or x to a marker using jQuery, it bleeds over and styles the other marker in the same row the same way. Looking to make them independent.
https://jsfiddle.net/sLy9d67r/
<div class="conjugate-input-container ">
<table class="table table-striped conjugate-input">
<tbody>
<tr>
<div>
<td class="subject">je</td>
<td class="conj-input"><input type="text" id="conj1sg" autocomplete="off" spellcheck="false" tabindex="-1" ></td>
<td class="marker"><i class="fa "></i></td>
</div>
<div>
<td class="subject">nous</td>
<td class="conj-input"><input type="text" id="conj1pl" autocomplete="off" spellcheck="false" tabindex="4" ></td>
<td class="marker"><i class="fa "></i></td>
</div>
</tr>
<tr>
<div>
<td class="subject">tu</td>
<td class="conj-input"><input type="text" id="conj2sg" autocomplete="off" spellcheck="false" tabindex="2" ></td>
<td class="marker"><i class="fa "></i></td>
</div>
<div>
<td class="subject">vous </td>
<td class="conj-input"><input type="text" id="conj2pl" autocomplete="off" spellcheck="false" tabindex="5" ></td>
<td class="marker"><i class="fa "></i></td>
</div>
</tr>
<tr>
<div>
<td class="subject">il</td>
<td class="conj-input"><input type="text" id="conj3sg" autocomplete="off" spellcheck="false" tabindex="3" ></td>
<td class="marker"><i class="fa "></i></td>
</div>
<div>
<td class="subject">ils</td>
<td class="conj-input"><input type="text" id="conj3pl" autocomplete="off" spellcheck="false" tabindex="6" ></td>
<td class="marker"><i class="fa "></i></td>
</div>
</tr>
</tbody>
</table>
</div>
Within a table, you can only insert other elements (eg, span div) in the td. Div's are not allowed between two tr(s) or two td(s).

Table with two tbody's next to each other in table, thead on top

I want to create an HTML table that looks like this:
Left context | Right context | Delete row?
-------------------------------------------
1 [input] [input] Y/N
2 [input] [input] Y/N
3 [input] [input] Y/N
This seems simple enough. The thing is that I want to make the rows sortable with jQuery UI. That's easy enough as well (call .sortable() on the tbody), however I find this very ugly because the number moves with the row. What I want is that only the "real" rows move, without the indices (1, 2, 3 and so on). Those numbers should always be in the same spot, but the rows can move around.
I thought I could simply make a new tbody inside the table, after the thead, which would only contain the numbers, and then call .sortable on the tbody that contains only the rows. However, obviously this doesn't work: the tables don't float next to each other, but are placed above each other.
Any ideas how to deal with this? Test case on JSFiddle:
<table class="table table-hover table-striped">
<thead>
<tr>
<th></th>
<th>Left context</th>
<th>Right context</th>
<th class="text-center">Delete row?</th>
</tr>
</thead>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
</tbody>
<tbody class="sortable">
<tr class="ui-state-default">
<td>
<input type="text" class="form-control left-context" value="">
</td>
<td>
<input type="text" class="form-control right-context" value="">
</td>
<td>
<button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
<tr class="ui-state-default">
<td>
<input type="text" class="form-control left-context" value="">
</td>
<td>
<input type="text" class="form-control right-context" value="">
</td>
<td>
<button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
<tr class="ui-state-default">
<td>
<input type="text" class="form-control left-context" value="">
</td>
<td>
<input type="text" class="form-control right-context" value="">
</td>
<td>
<button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
<tr class="ui-state-default">
<td>
<input type="text" class="form-control left-context" value="">
</td>
<td>
<input type="text" class="form-control right-context" value="">
</td>
<td>
<button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
<tr class="ui-state-default">
<td>
<input type="text" class="form-control left-context" value="">
</td>
<td>
<input type="text" class="form-control right-context" value="">
</td>
<td>
<button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
<tr class="ui-state-default">
<td>
<input type="text" class="form-control left-context" value="">
</td>
<td>
<input type="text" class="form-control right-context" value="">
</td>
<td>
<button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
</tbody>
</table>
I suggest using CSS counters in pseudo-elements displayed as table-cells:
$("tbody").sortable();
$("button").on("click", function () {
$(this).closest("tr").fadeOut(300);
});
#import 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css';
td {
padding: 8px;
}
thead > tr:before {
content: '';
display: table-cell;
}
tbody {
counter-reset: row-number;
}
tbody > tr:before {
counter-increment: row-number;
content: counter(row-number);
display: table-cell;
vertical-align: middle;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Left context</th>
<th>Right context</th>
<th>Delete row?</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><button type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><button type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><button type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><button type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><button type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><button type="button"><i class="fa fa-trash-o"></i></button></td>
</tr>
</tbody>
</table>

Table width can't be set below 385 pixels and responsiveness issue

I am using Bootstrap and have a part in my code that is:
<table class="table">...</table>
In my header, I have the tag <meta name="viewport" content="width=device-width"> This actually works fine(I can see the whole table on my website) but when I add <meta name="viewport" content="width=device-width initial-scale=1"> like is suggested on many websites, my table doesn't fit the 320 px width viewport that I have been using to test and I have to scroll to see the whole table.
Further investigation and playing around with the css for .table shows that I can't manually set width below 385 px. I have tried searching "bootstrap table 385 px" but it doesn't seem like there is anything special about this number so I am wondering why the table can't be smaller. Does anyone have any ideas as to how I can make the table smaller or make it scale correctly to initial-scale=1?
Edit #1:
<table class="table">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox" ng-model="..."> ...
</td>
<td>
<input type="checkbox" ng-model="..."> ...
</td>
<td width=70%>
<input class="form-control" ng-model="...">
</td>
<td>
<button class="btn btn-primary" ng-click="...">...</button>
</td>
</tr>
<tr ng-repeat="... in ...">
<td class="claimedby-{{...}}">
<input type="checkbox" ng-model="..." ng-click="..."> {{...}}
</td>
<td>
<input type="checkbox" ng-model="..." ng-click="..."> ...
</td>
<td>
<div for="...">
<div class="...">{{...}}</div>
</div>
</td>
<td>
<button class="btn btn-danger" ng-click="...">...</button>
</td>
</tr>
</tbody>
</table>
Sorry for the "..." in certain places. I'm not sure if we're allowed to post exact code publicly. Hopefully this is enough to see what's going wrong though.
Here, this should do it for you
<table class="table">
<thead>
<tr>
<th class="col-md-4 col-xs-2">Col1</th>
<th class="col-md-4 col-xs-2">Col2</th>
<th class="col-md-4 col-xs-8">Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox" ng-model="..."> ...
</td>
<td>
<input type="checkbox" ng-model="..."> ...
</td>
<td>
<input class="form-control" ng-model="...">
</td>
<td>
<button class="btn btn-primary" ng-click="...">...</button>
</td>
</tr>
<tr ng-repeat="... in ...">
<td class="claimedby-{{...}}">
<input type="checkbox" ng-model="..." ng-click="..."> {{...}}
</td>
<td>
<input type="checkbox" ng-model="..." ng-click="..."> ...
</td>
<td>
<div for="...">
<div class="...">{{...}}</div>
</div>
</td>
<td>
<button class="btn btn-danger" ng-click="...">...</button>
</td>
</tr>
</tbody>
</table>

Put a div at the beginning of a table cell

I having trouble trying to put a div with the style catalog at the top of the cell of a table. I don't know why because in the next column, I have a div and it appears in the right place.
What am I doing wrong?
The code, live at jsFiddle:
<table id="tblButtonContainer" style="margin:0px;border:0px; border-collapse: collapse; border-spacing: 0;">
<tbody>
<tr>
<td style="">
<div class="ui-accordion-header ui-helper-reset ui-state-default topCatalog">
Categorias
</div>
</td>
<td>
<div class="ui-accordion-header ui-helper-reset ui-state-default">
<label style="float:left;color:#FFF">Buscar</label>
<input id="txtFinder" class="txtInput" type="text" value="Buscar" size="40">
<input id="btnFinder" type="button" value="Buscar" class="ui-button ui-widget ui-state-default ui-corner-all" role="button">
</div>
</td>
</tr>
<tr>
<td style="padding-right: 20px">
<div class="catalog ui-accordion-header ui-helper-reset ui-state-default" style="200px">
<ul class="menuCat">
<li>
<label class="formatText">Accesorios 4x4</label>
<span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
</li>
<li>
<label class="formatText">Frenos y Pastillas</label>
<span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
</li>
<li>
<label class="formatText">Tren Delantero</label>
<span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
</li>
</ul>
</div>
</td>
<td>
<div id="catalogSearch" class="boxShadow">
<table id="tblCatalogSearch" class="centerTable" style="text-align:center">
<tbody>
<tr>
<td colspan="3">
<div style="margin:0;width:490px" class="ui-state-hover borders">
Elige el modelo de tu vehículo
</div>
<div style="height:20px"></div>
</td>
</tr>
<tr>
<td>
<label>Marca</label>
<select name="brand" id="brand">
<option value="0">Elige una Marca</option>
<option value="1">prueba</option>
</select>
</td>
<td>
<label>Modelo</label>
<select name="model" id="model" disabled="disabled"></select>
</td>
<td>
<label>Año</label>
<select name="year" id="year" disabled="disabled"></select>
</td>
</tr>
<tr><td><div style="height:20px"></div></td></tr>
<tr>
<td colspan="3">
<input name="btnSearch" id="btnSearch" value="Buscar" type="button" class="ui-button ui-widget ui-state-default ui-corner-all" role="button">
</td>
</tr>
</tbody>
</table>
</div>
<div id="results" class="boxShadow ui-corner-all borders" style="display: none; ">
<div style="margin:0;width:490px" class="ui-state-hover borders">
<span class="formatText" style="color:#373737;font-weight:bold;margin-left:20px">
Resultados de la Busqueda:
</span>
</div>
<table id="tblResult">
<tbody>
<tr></tr>
<tr><td>Uno</td></tr>
<tr><td>dos</td></tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
Note: I'm using jQuery-UI to help me with the styles I don't know if that is part of the problem.
Just add vertical-align:top; to your cell.
The default table cell behaviour is to vertically align to the centre. The second cell looks correct to you because it fills the whole cell. But it isn’t technically aligned to the top at all.
Use: #tblButtonContainer td {vertical-align: top;}.
Don't use inline styles!
You can also consider adding:
#tblButtonContainer td div {
display: table;
height: 100%;
width: 100%;
}
But I can't vouch for that in all browsers.