I have a table (using Bootstrap 3.0) with an input field in each cell
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<table id="itemTable" border="1" class="table table-bordered table-striped">
<thead>
<tr>
<th >Quantity</th>
<th>Unit</th>
<th>Material Name</th>
<th>PO Vatable</th>
<th>PO TAX</th>
<th>PO Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="number" min="1" class="form-control" name="Quan[]">
</td>
<td>
<select id="BX_gender" name="Unit[]">
<option>Kg</option>
<option>Piece</option>
<option>Meter</option>
<option>Pound</option>
<option>Gram</option>
<option>Feet</option>
</select>
</td>
<td><input type="text" name="Material[]"> </td>
<td><input type="number" step="0.01" class="small" name="POVATABLE[]"> </td>
<td><input type="number" step="0.01" class="small" name="POTAX[]"> </td>
<td><input type="number" step="0.01" class="small" name="POTOTAL[]" onkeyup="onRequestTotalModification(this.parentNode.parentNode.rowIndex)"> </td>
</tr>
</tbody>
</table>
I'm trying to set the input to have the width & height of the cell containing it, but nothing is working (even inline styling).
I organized the table using thead and tbody tags, but it didn't fix anything
If you're trying to have your input be the entire cell you need to remove bootstraps default padding on TD elements.
https://jsfiddle.net/2ay5yuq3/2/
.table-bordered>tbody>tr>td, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>td, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>thead>tr>th{
padding:0;
}
Related
In my Angular Application, I have created a simple Bootstrap Table. Here I want to show the table aligned properly with table headers th with corresponding input fields in td. How can I get th aligned equally with respect to their input fields in the table?
Here I need Name and Email for some input fields.
Here I have shared the jsfiddle link: https://jsfiddle.net/Venkata_Shivaram/8jnasgwr/
Here is my code:
<div class="table-responsive">
<table class="table" style="width: 100%;">
<thead class="card-header">
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
<th>Address</th>
<th>Email</th>
<th>Phone Number</th>
<th>Pincode</th>
<th>City</th>
<th>State</th>
<th>Region</th>
</tr>
</thead>
<tbody>
<tr>
<td class="required-field" colspan="2"><input type="text" class="form-control" formControlName="Name" placeholder="Name"></td>
<td class="required-field" colspan="1"><input type="text" class="form-control" formControlName="Age" placeholder="Age"></td>
<td class="required-field" colspan="1"><input type="text" class="form-control" formControlName="Country" placeholder="Country"></td>
<td class="required-field" colspan="1"><input type="text" class="form-control" formControlName="Address" placeholder="Addess"></td>
<td class="required-field" colspan="2"><input type="text" class="form-control" formControlName="Email" placeholder="email"></td>
<td class="required-field" colspan="1"><input type="text" class="form-control" formControlName="PhoneNumber" placeholder="phonenumber"></td>
<td class="required-field" colspan="1"><input type="text" class= "form-control" formControlName="pincode" placeholder="pincode"></td>
<td class="required-field" colspan="1"><input type="text" class="form-control" formControlName="city" placeholder="City"></td>
<td class="required-field" colspan="1"><input type="text" class="form-control" formControlName="state" placeholder="state"></td>
<td class="required-field" colspan="1"><input type="text" class="form-control" formControlName="Region" placeholder="Region"></td>
</tr>
</tbody>
</table>
I have tried with applying <colgroup> HTML element for th didn't work for me.
<colgroup>
<col>
<col span="2" class="batman">
<col span="2" class="flash">
</colgroup>
You have used colspan="2" for Name and Email. Make it colspan="1".
Read more about colspan here.
I have a table where the user can enter some values and transmit these inputs to my backend via a POST request.
Each row consists of a type, brand and some input fields like buyprice, bottom, top, and stop.
For the purpose that I can connect the input data with the backend data it is important to get the information about the brand which is unique in each row.
Because of that I implemented a hidden input field that the necessary pre-defined value.
But when I check my backend, I only receive the data about buyprice, bottom, top and stop. But nothing about the brand.
Here the relevant passage:
<td th:text="${car.getBrand()}">
<input type="text" name="brand" th:value="${car.getBrand()}" hidden>
</td>
Here the complete table (I use thymleaf as a template-engine)
<div class="container">
<br>
<h4 style="text-align: center">Please specify below</h4>
<br>
<form method="POST">
<table id="buyTable" class="table table-hover">
<thead>
<tr>
<th>Type</th>
<th scope="col">Brand</th>
<th scope="col">Buy-Price</th>
<th scope="col">Bottom</th>
<th scope="col">Top</th>
<th scope="col">Stop</th>
<th>Reduce</th>
<th>Start</th>
</tr>
</thead>
<tbody>
<tr th:each="car : ${cars}">
<td>
<select th:id="${car.getBrand()}" title="selectBuyOrSell" onchange="updateBuyTable(this)">>
<option value="buy">Buy</option>
<option value="sell">Sell</option>
</select>
</td>
<td th:text="${car.getBrand()}">
<input type="hidden" name="brand" th:value="${car.getBrand()}">
</td>
<td><input type="number" step="0.00000001" placeholder="Enter price" name="buyPrice" /></td>
<td><input type="number" step="0.00000001" placeholder="Enter bottom" name="bottom" /></td>
<td><input type="number" step="0.00000001" placeholder="Enter top" name="top" /></td>
<td><input type="number" step="0.00000001" placeholder="Enter stop" name="stop" /></td>
<td>
<label class="custom-control custom-checkbox">
<input id="clickboxReduce" type="checkbox" class="custom-control-input"
onclick="handleClickOnStart(this)" checked>
<span class="custom-control-indicator"></span>
</label>
</td>
<td>
<label class="custom-control custom-checkbox">
<input id="clickboxStart" type="checkbox" class="custom-control-input"
onclick="handleClickOnReduce(this)" checked>
<span class="custom-control-indicator"></span>
</label>
</td>
<!-- <td><input id="clickboxReduce" type="checkbox"></td>
<td><input id="clickboxStart" type="checkbox"></td>-->
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><a style="float:right">Select all</a></td>
<td style="text-align:center"><input type="checkbox" onclick="checkReduce(this)" checked></td>
<td style="text-align:center"><input type="checkbox" onclick="checkInstant(this)" checked></td>
</tr>
</tbody>
</table>
<br/>
<br/>
<button style="float: right!important;" class="btn btn-outline-primary">Continue</button>
<br/>
<br/>
<br/>
<table id="sellTable" class="table table-hover" hidden="true">
<thead>
<tr>
<th>Type</th>
<th>Brand</th>
<th scope="col">Sell-Price</th>
<th scope="col">Amount</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
</form>
</div>
So it is actually only about getting the brand. Any idea?
Thank you
I figured out that th:text="${car.getBrand()}" within the td tag was overriding the hidden input-field.
So the solution is an a tag and a hidden input within the td tag.
<td>
<a th:text="${car.getBrand()}"></a>
<input type="hidden" name="brand" th:value="${car.getBrand()}"/>
</td>
I have table and I would like to put my td's under th tags. Here is my HTML code:
<table>
<tr>
<th>Your Email</th>
<td>
<input type="text" name="userEmail" value="" id="userEmail" required="">
</td>
</tr>
<tr>
<th>Job Category</th>
//I need break line here
<td>
<label><input type="radio" name="rd1" value="Programmer" id="rd1">Programmer</label><br>
<label><input type="radio" name="rd2" value="Web Developer" id="rd2">Web Developer</label><br>
</td>
<tr>
</table>
My output gives me text in <th> tags and then text in <td> tags next to it. I would like to have td content below th. I tried to use <br> tags but looks like that does not work outside of td tags. If anyone know the best and way to fix this please let me know.
You are creating a table and nothing can be put outside the table cells. If you want to have the forms element under the headers, just create one row with headers and one row with forms elements:
<table>
<tr>
<th>Your Email</th>
<th>Job Category</th>
</tr>
<tr>
<td>
<input type="text" name="userEmail" value="" id="userEmail" required="">
</td>
<td>
<label><input type="radio" name="rd1" value="Programmer" id="rd1">Programmer</label><br>
<label><input type="radio" name="rd2" value="Web Developer" id="rd2">Web Developer</label><br>
</td>
<tr>
</table>
Put your table header in its own row:
<table>
<tr>
<th scope="row">Your Email</th>
<td>
<input type="text" name="userEmail" value="" id="userEmail" required="">
</td>
</tr>
<tr>
<th colspan="2">Job Category</th>
</tr>
<tr>
//I need break line here
<td colspan="2">
<label><input type="radio" name="rd1" value="Programmer" id="rd1">Programmer</label><br>
<label><input type="radio" name="rd2" value="Web Developer" id="rd2">Web Developer</label><br>
</td>
</tr>
</table>
Place them in different rows using
<table>
<tr>
<th scope="row">Your Email</th>
<td>
<input type="text" name="userEmail" value="" id="userEmail" required="">
</td>
</tr>
<tr>
<th>Job Category</th>
</tr>//End row
//I need break line here
<tr> //start new row
<td>
<label><input type="radio" name="rd1" value="Programmer" id="rd1">Programmer</label><br>
<label><input type="radio" name="rd2" value="Web Developer" id="rd2">Web Developer</label><br>
</td>
<tr>
</table>
I am using Bootstrap 2.3 and I have like 7 text input fields inside a table that uses bootstrap table style. I would like to resize (or shrink the width of) these text inputs instead of taking the whole width of the table cell but I could not do that
I tried to use the class of span1 but it did not shrink them well. So is there any way of minimizing the size or width of all text input fields within the table cell?
Here's my code:
<table class="table table-bordered">
<thead>
<tr>
<th>Exercise</th>
<th>Exercise Code</th>
<th>Initiated by</th>
<th>Initiated on</th>
<th>Done by</th>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
For Action
</td>
</tr>
</tbody>
</table>
Since you have access to JQuery, try doing this in your <header> area of html, but be sure it is after all Javascript includes.
<script type="text/javascript">
$(".span1").css("width", "10px");
</script>
If the above works, I think you need to update your original post to show all your js/css includes. This seems like you just have something in the wrong order.
--Original Answer Below--
Could you not simply add a CSS entry in your header like:
.table > input[type="text"] {
width: 10px;
}
The only negative is that this will change all table type=text elements that use the .table class.
So instead, have the table itself have the span1 tag and change the above code to reflect it?
.span1 > input[type="text"] {
width: 10px;
}
*Note: Make sure this is AFTER you reference the bootstrap css.
I have a table in bootstrap 3
<table class="table table-bordered table-condensed">
<tbody>
<tr>
<td><input type="text" class="form-control" /></td>
<td><input type="text" class="form-control" /></td>
<td><input type="text" class="form-control" /></td>
<td><input type="text" class="form-control" /></td>
<td><input type="text" class="form-control" /></td>
<td><input type="text" class="form-control" /></td>
</tr>
</tbody>
</table>
Can I make the input fields look like normal cells? I want the input fields to fill out the entire cells (without no input margin nor table cell padding). Just like an Excel spreadsheet where I have many cells and can write in each of them.
Yup. Do it this way:
input {display: block; padding: 0; margin: 0; border: 0; width: 100%;}
td {margin: 0; padding: 0;}
Fiddle: http://jsbin.com/biqomurafage/1
You could also try using contentEditable tables like this: DEMO
<table>
<tbody>
<tr>
<th></th>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>
<tr>
<th>1</th>
<td><span id="A1" contenteditable>#####</span></td>
<td><span id="B1" contenteditable></span></td>
<td><span id="C1" contenteditable></span></td>
</tr>
<tr>
<th>2</th>
<td><span id="A2" contenteditable></span></td>
<td><span id="B2" contenteditable></span></td>
<td><span id="C2" contenteditable></span></td>
</tr>
</tbody>
</table>
span {
width: 100%;
display: block;
}
*note, the content editable spans are required for IE to handle the contentEditable attributes correctly. Reference