Using angularjs with bootstrap 3 here.
I am trying to create dynamic rows when user clicks button. I have wrapped this inside a table and using ng-repeat.
When the second row is added it creates a separation b/w the two.
Below is my code:
<table class="table table-borderless">
<thead>
<tr>
<td>Text</td>
<td>Value</td>
</tr>
</thead>
<tbody ng-repeat="m in options">
<tr>
<td>{{m.Name}}</td>
<td>{{m.Country}}</td>
<td>
<a class="btn btn-xs" ng-click="Remove($index)"><i class="glyphicon glyphicon-trash"></i></a>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<input type="text" class="form-control" ng-model="Name" required />
</td>
<td>
<input type="text" class="form-control" ng-model="Country" required />
</td>
<td>
<a class="btn btn-xs" ng-click="Add()"><i class="glyphicon glyphicon-plus"></i></a>
</td>
</tr>
</tfoot>
</table>
I also created a demo at:
http://jsfiddle.net/Lyxbhosv/
Any inputs on how to remove the line or border in between two TD
I am not entirely sure what you're asking but via your example there is a double border whenever another row is added. To remove the double border and keep it a single just modify your code with the following:
<tbody ng-repeat="m in options" style="border: none;">
If you can explain further that would be great!
While I'm examining your code you have already awarded the answer. But here I'm coming up with what I have learned from your code and this answer:
<tbody ng-repeat="m in options" style="border: none;"> This will create lots of Repeatable `' in your code.
But if you placed your code 'ng-repeat="m in options"' to the child <tr>' tag it will repeat the ` each time. and it will not create any repeatable border any more.
<tbody>
<tr ng-repeat="m in options">
So the choice is yours!
Related
<table>
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td>
<div style="display:inline-block;width:25%">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
<div style="display:inline-block;width:25%">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
I want it to auto jump to next line if the label text overflow. I no want the label to be hidden or using ellipsis.
Note: In my case, i will loop the div content in the same row td. I want to break the word to next line in full size of browser or browser resized to smaller.
How can i solve this problem?
Apologies for having too less reputation to post a comment.
But have you checked out Bootstrap tables?
It not only solves your problem, but is a good step in moving towards simple web development.
Bootstrap takes care of everything and allows us to make neat and clean tables with very little code from our side.
If at all you need to further style your table, you can add styling OVER the bootstrap styled table.
Check out the following simple tutorial where you can also try it out online.
https://www.w3schools.com/bootstrap/bootstrap_tables.asp
To prove how simple it is,
I have pasted my code into a simple HTML page.
Added bootstrap.
And voila! Your issue is solved in the example given below.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<table class="table">
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td>
<div>
<label>abcdefghijklmnop</label>
</div>
<div>
<input type="checkbox">
</div>
<div>
<label>abcdefghijklmnop</label>
</div>
<div>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td> <label>abcdefghijklmnop</label> </td>
<td> <input type="checkbox"> </td>
</tr>
<tr>
<td> <label>abcdefghijklmnop</label> </td>
<td> <input type="checkbox"> </td>
</tr>
</tbody>
</table>
</body>
</html>
I am still confused on what you wanted, so I have included 2 approaches.
Try Float:right;
<table>
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td>
<div style="display:inline-block;width:25%">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
<div style="display:inline-block;width:10%; float:right;">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
You can use word-wrap: break-word for your label tag.
The word-wrap property allows long words to be able to be broken and wrap onto the next line. break-word allows unbreakable words to be broken
<table>
<thead>
<tr>
<th>Item</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div style="display:inline-block;width:25%">
<label style="display:block;word-wrap: break-word;">abcdefghijklmnop</label>
<input type="checkbox">
</div>
<div style="display:inline-block;width:10%">
<label style="display:block;word-wrap: break-word;">abcdefghijklmnop</label>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
MDN web docs word-wrap
So...I have literally scoured the internet looking for a solution to this problem and haven't found any answer that directly (or indirectly) suggests an answer.
I am trying to create multiple forms within a table with each row being wrapped in <form> tags like so
<tr ng-repeat="item in items">
<form ng-submit="updateItem(item)">
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button>Submit</button></td>
</form>
</tr>
It seemed to work as intended until I realized that ng-repeat was not wrapping the <form> tag around the <td> tags and it ended up looking like so
<tr ng-repeat="item in items">
***<form ng-submit="updateItem(item)"></form>*** //The form tags were unwrapped
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td>
***<button>Submit</button>*** //Buttons don't submit cos no form
</td>
</tr>
whilst what I really want to achieve is something like
<tr>
<form>
<td>
<button>Hi</button>
</td>
</form>
</tr>
<tr>
<form>
<td>
<button>Hello</button>
</td>
</form>
</tr>
I would really love some help with how to deal with this.
You can unite cells:
<tr ng-repeat="item in items">
<td colspan="3">
<form ng-submit="updateItem(item)">
...
</form>
</td>
</tr>
Or use ngForm directive instead of form (and add submit on enter manually):
<tr ng-repeat="item in items" ng-form="myForm">
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button type="button" ng-click="updateItem(item)">Submit</button></td>
</tr>
You can add a new table in every row like this;
<table>
<tr ng-repeat="item in items">
<td>
<form ng-submit="updateItem(item)">
<table>
<tr>
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button>Submit</button></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
Well, thanks to #pegatron and the Stack Overflow link he provided using #tjbp answer I ended up using the form attribute of input fields and that did it for me. Though its not been tested on all browsers, it does the trick of HTML5 validations. Here's what I ended up with.
<tr ng-repeat="item in items">
<form ng-submit="updateItem(item)" id="{{item.title}}">
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button form="{{item.title}}">Submit</button></td>
</form></tr>
And with this the form and its linked inputs gets sent with the button click.
Thanks.
I have a table with list elements that I want to be able to skip through using arrow keys. Right now I have to click on the table element border before I can use the arrow keys. If I set tabindex on one of the elements in the loop, it doesn't work. So, how can I focus tabindex on a table element when it is clicked?
<section ng-controller="PlaylistCtrl" >
<table class="table table-striped table-hover " ng-keyup="keyPress($event.keyCode, $index)" tabindex="1">
<thead>
<tr>
<th>
<button type="button" ng-click="toSubmit()" class="btn btn-default">Add resource
</button>
</th>
</tr>
</thead>
<tbody ui-sortable ng-model="result">
<tr ng-repeat="resource in result">
<td ng-class="isSelected(resource)">
<div ng-click="showResource(resource, $index)">
{{resource.name}}
</div>
</td>
<td ng-class="isSelected(resource)" style="width: 15px;"><span class="glyphicon glyphicon-remove" id="sidebarEdit" ng-click="removeResource(resource, $index)"></span></td>
</tr>
</tbody>
</table>
</section>
document.getElementById('table_id').focus();
I am making a form for inserting recipes to my database, whenever im dealing with forms, i always go for simplicity -> tables.
For example i have this code:
<table>
<tr>
<td>
<tr>Text:</tr>
<tr>
<input type="button" />
</tr>
</td>
<td>
<input type="text" />
</td>
</tr>
</table>
I wanted to have 2 rows inside a column, The above code doesnt actually work, im just demonstrating on how i would like it to arrange.
Is there anyway to do this? or do i have to resort to using divs and CSS(ugghh,, i hate this part. trial and error on the location.....)
<table>
<tr>
<td>
<table>
<tr>
<td>Text:</td>
</tr>
<tr>
<td><input type="button" /></td>
</tr>
</table>
</td>
<td>
<input type="text" />
</td>
</tr>
I have a table I decorated with bootstrap.
Here is the simple table view (collapsed).
Each table row has two horizontal sets of data. So the expanded view for each row shows up when the "Details" button is clicked. Here's the expanded view.
The first set of data of each row has 4 columns. While I'd like the second set of data of the same row to fully occupy the whole table width.
The problem is that the way I did it doesn't feel the best way to do it.
I pretty much used Angular loop construct to repeat the <tr>. I then embedded two tables per <tr> so that I can display the first data set in the first table and the expanded view in the second table. Clicking on the "Details" button shows the second set (table) of data of row.
<table class="table-hover table-condensed">
<!--<table class="table">-->
<thead>
<tr>
<th align="left" class="span2">Date</th>
<th align="left" class="span2">Title</th>
<th align="left" class="span2">Bill Total</th>
<th align="left" class="span4">Options</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ibill in user.groups[0].bills | filter:query | orderBy:'date'">
<td colspan="4">
<table>
<tr>
<td class="span2">{{ ibill.billDate | date:'MM/dd/yyyy'}}</td>
<td class="span2">{{ ibill.title }}</td>
<td class="span2">${{ ibill.billTotal }}</td>
<td class="span4">
<!-- <a ng-click='deleteBill(ibill.id)'><i class="icon-trash "></i></a>
<i class="icon-pencil "></i>--> <a ng-click='deleteBill(ibill.id)' class="btn btn-mini" ng-init="ibill.isCollapsed = 'true'" ng-click="ibill.isCollapsed = !ibill.isCollapsed"><i class=" icon-trash"></i></a>
<i class="icon-edit"></i>
<a class="btn btn-mini" ng-init="ibill.isCollapsed = 'true'" ng-click="ibill.isCollapsed = !ibill.isCollapsed"><i class="icon-eye-open"></i> details</a>
<!--<a class="btn" ng-init="ibill.isCollapsed=' true'" ng-click="ibill.isCollapsed=! ibill.isCollapsed"><i class="icon-folder-open "></i> Details</a>-->
</td>
</tr>
</table>
<table>
<tr>
<td colspan="4">
<div collapse="ibill.isCollapsed">
<div>
<p ng-repeat="simplecost in ibill.billSimpleEntry.simpleUserIdAndLiableCost">{{simplecost.user.fName}} owes ${{simplecost.liableCost}}</p>
</div>
</div>
</td>
</tr>
</table>
</td>
<!--<td>{{ibill}}</td>-->
</tr>
<!-- <tr>
<td><div collapse="ibill.isCollapsed">
<div class="well well-large">Some content</div>
</div></td>
</tr>-->
</tbody>
</table>
I'm pretty much e
<table>
<thead></thead>
<tbody>
<tr>
<td></td>
</tbody>
</table>
Is it possible to do the same with a table-less design (eliminating two tables per row)
You could just use the colspan attribute on a td to achieve the same effect without the tables. Ex:
<table>
<tbody>
<tr> <!--normal row stuff-->
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan='4'><!--details stuff here--></td>
</tr>
</tbody>
</table>
In this example, the td with colspan='4' will be a single cell that is the same width as the 4 cells in the previous row.