How to control the width of a table with-in table - html

Here is the page source
<div class="col-xs-12">
<br />
<div class="panel panel-primary">
<div class="panel-heading">
Collection Info
</div>
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane active">
<table class="table" >
<tr>
<th>Vendor</th>
<th>Claim Amount</th>
<th>Amount Received</th>
<th>Type</th>
</tr>
<tr>
<th>Date</th>
<th>Rep</th>
<th>Notes</th>
</tr>
<tr>
<td>
Difference in State Check
</td>
<td>
0.00
</td>
<td>
-382.19
</td>
<td>
<select class="form-control" data-val="true" data-val-required="The Value field is required." id="item_Type_Value" name="item.Type.Value">
<option selected="selected" value="c6edd5bc-c5ef-4a56-8db2-17905d98c823">--None--</option>
<option value="0b4a44d0-7241-422d-935b-d0606b9c5ce1">Attn</option>
<option value="a1341e3c-afb7-4c47-8040-d33bdf82493b">$$$</option>
</select>
<p />
<div class="col-xs-12" style="text-align: right;">
<div class="form-group">
<label class="col-xs-5 control-label"></label>
<div class="col-xs-7">
<input type="submit" value=" Update " style="height:35px;width:75px;" />
</div>
</div>
</div>
</td>
<td>
0.00
</td>
<td>
</td>
<td>
999-999-9999
</td>
</tr>
<tr>
<td>
<textarea cols="80" htmlAttributes="{ class = form-control }" id="Notes" name="Notes" rows="6">
</textarea>
</td>
</tr>
</table>
I'm using bootstrap and below is the picture of my page.
My question is: How can I have Vendor, Claim Amount, Amount Received, Type with-in the div of Collection Info?
so I'm rendering this page using two loops
the first loop generates - vendor, claim amount, amount received, type
the second loop generates - date,rep,notes
and the reason my page is messed up is due to my textarea
here is my html page looks like:
<div class="col-xs-12">
<br />
<div class="panel panel-primary">
<div class="panel-heading">
Collection Info
</div>
<br />
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane active">
<table class="table" >
<tr>
<th>Vendor</th>
<th>Claim Amount</th>
<th>Amount Received</th>
<th>Type</th>
</tr>
<tr>
<th>Date</th>
<th>Rep</th>
<th>Notes</th>
</tr>
#foreach (var item in Model)
{
<tr><td>#item.vendor</td></tr>
<tr>#item.claimamount</td></tr>
<tr>#item.amountreceived</td></tr>
<tr>#item.type</td></tr>
foreach (var item1 in item.DetailViewModel)
{
<tr>
<td>
#item1.Date
</td>
<td>
#item1.Rep
</td>
<td>
#item1.Notes
</td>
</tr>
}
<tr>
<td>
#Html.TextArea("Notes", "", 6, 80)
</td>
</tr>
}
</table>
</div>
</div>
</div>
</div>
</div>
I'm trying to achieve something like this:

[This solution takes into consideration the generated code from the edit]
As I told you in the comment, just by fixing the different colspan in the table, it already looks a lot better (and closer to what you show in your picture): http://jsfiddle.net/wnqLpsv9/
For example, if the rows have 7 columns, make all the rows have 7 columns (or occupy the space of 7 columns using colspan), or the result will depend on how the browser decides to display the table.
Still, you need to look at the source, because this is a mess of unnecessary <tr> and closing </td> without opening <td>, that won't generate valid code:
#foreach (var item in Model)
{
<tr><td>#item.vendor</td></tr>
<tr>#item.claimamount</td></tr>
<tr>#item.amountreceived</td></tr>
<tr>#item.type</td></tr>
foreach (var item1 in item.DetailViewModel)
{
<tr>
<td>
#item1.Date
</td>
<td>
#item1.Rep
</td>
<td>
#item1.Notes
</td>
</tr>
}
<tr>
<td>
#Html.TextArea("Notes", "", 6, 80)
</td>
</tr>
}
From what you show in the picture, it would need to be something more in this line (and notice that I don't claim this is correct, but more of a guideline on how to fix it):
#foreach (var item in Model)
{
<tr>
<td>#item.vendor</td>
<td>#item.claimamount</td>
<td>#item.amountreceived</td>
<td>#item.type</td>
</tr>
foreach (var item1 in item.DetailViewModel)
{
<tr>
<td>
#item1.Date
</td>
<td>
#item1.Rep
</td>
<td colspan="2">
#item1.Notes
</td>
</tr>
}
<tr>
<td colspan="2"></td>
<td colspan="2">
#Html.TextArea("Notes", "", 6, 80)
</td>
</tr>
}

Related

how to expand/collapse table rows using jquery?

I am trying to expand/collapse the following row if row with class='sector' is clicked
This same code seems to work for many people as per other stackoverflow answers but it is not working for me and I wonder why? I do not know much jquery but this seems to me to be workable but still does not work.
Kindly give a simple solution
$(document).ready(function() {
$("td[colspan=2]").hide();
$("tr.sector").click(function() {
$(this).next().toggle();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="table-responsive">
<table class="table">
<tr>
<td scope="col">Sector</th>
<td scope="col">Total Qty</th>
</tr>
<tr class="sector">
<td>Sector no. 2</td>
<td>
M : 1, </td>
</tr>
<tr>
<td colspan="2">
<p>
<div>
<div class="row">
<div class="col-4">Plot no. 5 | NPSC Apartment</div>
<div class="col-4">1 Packets</div>
<div class="col-4">Details</div>
</div>
</div>
</p>
</td>
</tr>
<tr class="sector">
<td>Sector no. 3</td>
<td>
M : 2, MJ : 1, </td>
</tr>
<tr>
<td colspan="2">
<p>
<div>
<div class="row">
<div class="col-4">Plot no. 1 | Heritage Tower (Sawan CGHS)</div>
<div class="col-4">1 Packets</div>
<div class="col-4">Details</div>
</div>
<div class="row">
<div class="col-4">Plot no. 8 | Himachali Apartment</div>
<div class="col-4">2 Packets</div>
<div class="col-4">Details</div>
</div>
</div>
</p>
</td>
</tr>
</table>
</div>
</div>
You are hiding the td[colspan=2] inside tr and trying to toggle that same tr without actuality showing the td you have hidden in first place.
So you need to use next to get next tr sibling and find inside td[colspan=2] you have hidden and toggle that.
Please read documentation on Jquery Tree Traversal and next time watch for your HTML tree. Its all well documented and explained on link provided.
$(document).ready(function() {
$("tr > td[colspan=2]").hide();
$("tr.sector").click(function() {
$(this).next().find("td[colspan=2]").toggle();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="table-responsive">
<table class="table">
<tr>
<td scope="col">Sector</th>
<td scope="col">Total Qty</th>
</tr>
<tr class="sector">
<td>Sector no. 2</td>
<td>
M : 1, </td>
</tr>
<tr>
<td colspan="2">
<p>
<div>
<div class="row">
<div class="col-4">Plot no. 5 | NPSC Apartment</div>
<div class="col-4">1 Packets</div>
<div class="col-4">Details</div>
</div>
</div>
</p>
</td>
</tr>
<tr class="sector">
<td>Sector no. 3</td>
<td>
M : 2, MJ : 1, </td>
</tr>
<tr>
<td colspan="2">
<p>
<div>
<div class="row">
<div class="col-4">Plot no. 1 | Heritage Tower (Sawan CGHS)</div>
<div class="col-4">1 Packets</div>
<div class="col-4">Details</div>
</div>
<div class="row">
<div class="col-4">Plot no. 8 | Himachali Apartment</div>
<div class="col-4">2 Packets</div>
<div class="col-4">Details</div>
</div>
</div>
</p>
</td>
</tr>
</table>
</div>
</div>

Design alignment prob in HTML

I have this picture below that I want to convert into web from a windows. I manage to do the design but I have a problem in the grid (I am using data tables in bootstrap) I can't do the design in what in the picture like.
<table>
<tr>
<td>
<div>
<input type="radio" />
Radio Button
</div>
</td>
<td>
<input type="radio" />
Radio Button
</td>
</tr>
<tr>
<td>
<div>
<input type="text" />
</div>
</td>
<td>
< div>
< input type="button" />
</div>
</td>
</tr>
</table >
<table >
<tr>
<td>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
< i class="fa fa-list fa-fw" >< / i >Table
< /div >
< /div>
< /div>
< !-- /.panel-heading -->
< div class="panel-body">
< div class="dataTable_wrapper">
< table class="table table-striped table-bordered table-hover table-responsive nowrap"
role="grid" style="width: 100%;" id="dataTables-xxxx">
</table>
</div>
</div>
</div>
</div>
< /div>
</td>
<td>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
< i class="fa fa-list fa-fw"></i>Table
< /div>
< /div>
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover table-responsive nowrap"
role="grid" style="width: 100%;" id="dataTables-xxasdxx">
</table>
< /div>
< /div>
< /div>
< /div>
< /div>
</ td>
< /tr>
< /table>
My 2 Images bellow:
Try the below design hope it helps.You can customize the column property as your desire I just added the basic skeleton.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container">
<div class="row">
<div class=" col-sm-12 form-group">
<div class=" col-sm-2">
<input type="radio" />
Radio Button
</div >
<div class=" col-sm-2">
<input type="radio" />
Radio Button
</div >
</div >
<div class=" col-sm-12 form-group ">
<div class=" col-sm-2">
<input type="text" class="form-control" id="usr">
</div>
<div class=" col-sm-2">
<button type="button" class="btn btn-default">Submit</button>
</div>
</div>
<div class="table-responsive col-md-6">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-1">#</th>
<th class="col-md-2">Header</th>
<th class="col-md-3">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive col-md-6">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-1">#</th>
<th class="col-md-2">Header</th>
<th class="col-md-3">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
Or See the below fiddle for a better look
table design demo fiddle (updated)
You can also, do something like this instead of using tables for layout and mimic as close as to your conversion UI.
table tags are meant primarily for data formatting. Bootstrap has the concept of grid layout which is meant for laying out your UI without using tables.
When you open the snippet in full screen, you would see the exact replica. However, when the screen is too small to fit in your entire content, it just wraps into the next row, giving you the flexibility to build responsive layout, which is not possible with table tags.
.custom-margin {
margin-top: 10px;
margin-bottom: 10px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="custom-container">
<div class="radio">
<label class="radio-inline">
<input type="radio" name="" id="optionsRadiosOne" value="optionOne">Radio Button One
</label>
<label class="radio-inline">
<input type="radio" name="" id="optionsRadiosTwo" value="optionTwo">Radio Button Two
</label>
</div>
<div class="custom-margin">
<form class="form-inline">
<div class="form-group">
<label for="exampleInputName2">Enter Email :</label>
<input type="text" class="form-control" placeholder="Enter Email">
</div>
<button type="submit" class="btn btn-primary">Send invitation</button>
</form>
</div>
<div class="row">
<div class="col-lg-3">
<table class="table table-hover">
<tr>
<td>Header One
</td>
<td>Header Two
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
</table>
</div>
<div class="col-lg-6">
<table class="table table-hover">
<tr>
<td>Header One
</td>
<td>Header Two
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
</table>
</div>
</div>
</div>

Dispay data from database to textbox asp.net mvc

How will I properly display data from database to textbox when the button "search" is clicked? It should display the item name and the price of that product code
enter image description here
Controller
public ActionResult Index(string searchString)
{
using(MyDatabaseEntities db = new MyDatabaseEntities())
{
var products = from s in db.Products
select s;
if (!String.IsNullOrEmpty(searchString))
{
products = products.Where(s => s.ProductCode.Equals(searchString));
}
return View(products.ToList());
}
}
Index
<div class="form-group">
<table style="text-align:left; margin-bottom:10px;">
<tr>
<td>Item Code</td>
<td>#Html.TextBox("SearchString")
</td>
<tr style="background-color:lightgray;">
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="btn btn-block btn-info"id="buttonsearch" value="Search" />
</td>
</tr>
<tr>
<td> </td>
</tr>
#foreach (var item in Model) {
<tr>
<td style="text-align:left;">Item Name</td
<td>#Html.DisplayFor(modelItem=> item.ProductName)</td>
</tr>
<tr>
<td>Unit Price</td>
<td style="text-align:right;">#Html.DisplayFor(modelItem => item.Price)</td>
</tr>
}
<tr>
<td style="text-align:left;">Quantity</td>
<td>
<input type="text" id="quantity" class="input-sm" />
<span class="error">Product Name required</span>
</td>
</tr>
<tr>
<td style="text-align:left;">Discount</td>
<td>
<input type="text" id="discount" class="input-sm" style="text-align:right;" placeholder="0.00" />
<span class="error">Product Name required</span>
</td>
</tr>
</table>
</div>
Instead of .ToList() use .FirstOrDefault(); just in case you want to populate one record in your textbox.

Bootstrap column offsetting

I've been trying this without luck. I want to have 5 columns within bootstrap, each "2" width. I want to offset the second column so that there is a "2" offset between column one and two. What we end up with is this:
2 Width Pricing Table - 2 Width Space - 2 Width Pricing Table - 2 Width Pricing Table - 2 Width Pricing Table - 2 Width Pricing Table.
Here is my code: http://www.bootply.com/MxnvNuTU6Q
<div class="col-md-2">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Bronze
</h3>
</div>
<div class="panel-body">
<h1>
$10<span class="subscript">/mo</span>
</h1>
<small>1 month FREE trial</small>
<table class="table">
<tbody>
<tr>
<td>
1 Account
</td>
</tr>
<tr class="active">
<td>
1 Project
</td>
</tr>
<tr>
<td>
100K API Access
</td>
</tr>
<tr class="active">
<td>
100MB Storage
</td>
</tr>
<tr>
<td>
Custom Cloud Services
</td>
</tr>
<tr class="active">
<td>
Weekly Reports
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-2 col-md-offset2">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Bronze
</h3>
</div>
<div class="panel-body">
<h1>
$10<span class="subscript">/mo</span>
</h1>
<small>1 month FREE trial</small>
<table class="table">
<tbody>
<tr>
<td>
1 Account
</td>
</tr>
<tr class="active">
<td>
1 Project
</td>
</tr>
<tr>
<td>
100K API Access
</td>
</tr>
<tr class="active">
<td>
100MB Storage
</td>
</tr>
<tr>
<td>
Custom Cloud Services
</td>
</tr>
<tr class="active">
<td>
Weekly Reports
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-2">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Bronze
</h3>
</div>
<div class="panel-body">
<h1>
$10<span class="subscript">/mo</span>
</h1>
<small>1 month FREE trial</small>
<table class="table">
<tbody>
<tr>
<td>
1 Account
</td>
</tr>
<tr class="active">
<td>
1 Project
</td>
</tr>
<tr>
<td>
100K API Access
</td>
</tr>
<tr class="active">
<td>
100MB Storage
</td>
</tr>
<tr>
<td>
Custom Cloud Services
</td>
</tr>
<tr class="active">
<td>
Weekly Reports
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-2">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Bronze
</h3>
</div>
<div class="panel-body">
<h1>
$10<span class="subscript">/mo</span>
</h1>
<small>1 month FREE trial</small>
<table class="table">
<tbody>
<tr>
<td>
1 Account
</td>
</tr>
<tr class="active">
<td>
1 Project
</td>
</tr>
<tr>
<td>
100K API Access
</td>
</tr>
<tr class="active">
<td>
100MB Storage
</td>
</tr>
<tr>
<td>
Custom Cloud Services
</td>
</tr>
<tr class="active">
<td>
Weekly Reports
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-2">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Bronze
</h3>
</div>
<div class="panel-body">
<h1>
$10<span class="subscript">/mo</span>
</h1>
<small>1 month FREE trial</small>
<table class="table">
<tbody>
<tr>
<td>
1 Account
</td>
</tr>
<tr class="active">
<td>
1 Project
</td>
</tr>
<tr>
<td>
100K API Access
</td>
</tr>
<tr class="active">
<td>
100MB Storage
</td>
</tr>
<tr>
<td>
Custom Cloud Services
</td>
</tr>
<tr class="active">
<td>
Weekly Reports
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
What have I done wrong, is col-md-offset2 not the right class?
col-md-offset2
should be
col-md-offset-2
That should create a gap between the first and second columns.

(bug) foreach jsp creating an empty tr tag on each iteration

This is my jsp code:
<table class="table table-striped">
<thead>
<tr>
<th>
Column name
</th>
</tr>
</thead>
<tbody>
<c:forEach var="question" items="${questions}">
<tr>
<td>
<h4>${question.sequence} - ${question.questionText}</h4>
<c:forEach var="answer" items="${question.answers}">
<div class='answer'>
<input type='radio' name="question${question.id}" id='${answer.id}'/>
<label for='${answer.id}'> ${answer.answerText}</label>
</div>
</c:forEach>
</td>
<tr>
</c:forEach>
</tbody>
</table>
When the page is printed, this code is creating an empty tr tag after each iteration and the result on html is:
<tbody>
<tr>
<td>
<h4>1 - Question 1?</h4>
<div class="answer">
<input type="radio" name="question1" id="1">
<label for="1">Answer 1.</label>
</div>
<div class="answer">
<input type="radio" name="question1" id="2">
<label for="2">Answer 2.</label>
</div>
</td>
</tr>
<tr>
</tr>
...... (some more iterations with the same result - a question and a empty tr tag)
</tbody>
Anyone knows what's happening with my code??
You are not closing the tr in the loop. You are missing the / in the closing tr. The second <tr> is causing the new row to be output.