backbone js append view [duplicate] - html

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Backbone js: How to remove extra tag in view?
How come whenever I append a new backbone view to an HTML element, it automatically surrounds this view with a <div> </div>?
For example I have a table in my HTML page
<table class="table table-hover">
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
</tr>
</thead>
<tbody id="tbl">
</tbody>
</table>
Now in my backbone controller, I perform the following
$("#tbl").append(new tblview().render().el);
and in the actual view's HTML template I have
tblview.html
<tr>
<td>entry3</td>
<td>entry4</td>
</tr>
Now when i look at this in the browser, and inspect the html element.. it renders like this:
<table class="table table-hover">
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
</tr>
</thead>
<tbody id="tbl">
<div>
<tr>
<td>entry3</td>
<td>entry4</td>
</tr>
</div>
</tbody>
</table>
and thus is becomes all out of line? How can I fix this issue??
I want it to render the view without these extra <div> </div> in the table.

Backbone automatically create a div to surround any view. To overwritte the default, you need to set the tagName attribute when you extend a view. http://backbonejs.org/#View-extend
Backbone.View.extend({
tagName: "tr"
});

Your template doesn't need to include the tr tags. tblView should have tagName set to tr.

Related

Having issues with ng-href i can use target="_blank" using AngularJS 1.2

I have issues with data values in a table and I'm trying to wrap the data in anchor tags so that it can be a downloadable link i tried to use ng-href but i can use target. is there an easier way of doing this? i was the data to show normally on the browser and have use click on it to download an image. but it shows an ugly anchor tag as well :/ this is my code with normal a href
i have tried using this as well, which was an answer for angular.js link behaviour - disable deep linking for specific URLs
<td><a target="_self" href="//tomcmmsweb.pca.com/DocumentLibrary/Download/{{item.documentId}}">{{item.jobNumber}}</a></td>
but above still didnt work. im using angularJS 1.2.16, im running out of ideas and im notthat much of an expert with angularJS. would really appreciate some knowledge.
<table class="table table-striped table table-hover">
<thead>
<tr>
<th>Project Manager</th>
<th>Job Number</th>
<th>Description</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in counce">
<td>{{item.projectManager}}</td>
<td>{{item.jobNumber}}</td>
<td>{{item.description}}</td>
<td>{{item.totalAmount*1000 | currency}}</td>
</tr>
</tbody>
</table>

Attaching an Href to a row inside a table

I am using html in a .php file to code. I have a statement:
<html>
<tr>
<td>Hi<td>
<td>Test<td.
</tr>
</html>
How can I attach an href to the row? Simply adding href in the tag didn't work. Anybody know how? Note: The table was defined earlier in the code this is the snip-it portion of the row.
You do not attach href to row instead you better do as
<table class="table table-stripped">
<tr class="selectedRow">
<td>Hi</td>
<td>Test</td>
</tr>
</table>
then using jquery :
$('.selectedRow').click(function(){
alert('do something');
});
View LiveWeave

How to extract only the 1st table tag from a html page having various nested table tag

I have the following html page. I want to extract data only within the 1st table tag in C#. the html page code is:
<table cellpadding=2 cellspacing=0 border=0 width=100%>
<tbody>
<tr>
<td align=right><b>11/09/2013 at 09:48</b></td>
</tr>
</tbody>
</table>
<center>
<table border="1" bordercolor="silver" cellpadding="2" cellspacing="0" width="100%">
<thead>
<tr>
<th width=100>ETA</th>
<th width=100>Ship Name</th>
<th width=80>From port</th>
<th width=80>To berth</th>
<th width=130>Agent</th>
</tr>
</thead>
<tbody>
<tr><td>11/09/2013 at 09:00 </td>
<td>SONANGOL KALANDULA </td>
<td>Cabinda </td>
<td>Valero 6 </td>
<td>Graypen </td>
</tr>
</tbody>
</table>
To be more specific I want to extract only the row having date 11/09/2013 at 09:48 the below mentioned code is under the first of tag I am using regex
"<table[^>]*>([^<]*(?:(?!</table)<[^<]*)*)[</table>]*"
but with this I am getting whole of the page source that is I am getting the data between all the table tags but I want only text between first table tag.
Can anyone tell me regular expression with which I can only extract this particular portion from the whole html page?
When trying out your version here, it seems to work to me on the input you specified, though [</table>]* should really be just </table> ([</table>]* means any number of characters in the set: <,/,t,a,b,l,e,>)
This seems like it would bear simplification, though. This should also work:
<table[^>]*>.*?</table>
All bets are off if you have nested tables, of course.

HTML Tables - can I have an additional tbody before the thead?

I need add to some elements on top of a table in line with the columns of the said table.
This table contains a <thead> (which is required due to jquery.tablesorter plugin). I assumed that if I put another <tbody> on top of the <thead> I would be able to keep these elements in line with the rest of the columns, but both chrome and firefox render every <tbody> below the <thead>.
Example:
<table>
<tbody>
<tr>
<td>1</td><td>1</td><td>1</td>
</tr>
</tbody>
<thead>
<tr>
<th>head</th><th>head</th><th>head</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td><td>2</td><td>2</td>
</tr>
<tr>
<td>3</td><td>3</td><td>3</td>
</tr>
<tr>
<td>4</td><td>4</td><td>4</td>
</tr>
</tbody>
</table>
Although I understand this, I still need to find a way to have these elements stay in line with specific columns.
You can use multiple rows in <thead> like this:-
<table>
<thead>
<tr> <td>1</td> <td>1</td> </tr>
<tr> <td>head</td> <td>head</td> </tr>
</thead>
</table>
I recommend that you use an id (#) marker to identify that part that you want the js to work off and have the js use that id.
With that, have the thead first and the tbody last.
The variations you are describing may work - in the browser you using now, on the OS you are ok - and may be compliant a certain version of the HTML spec- but putting things in an unusual order is (in my expereince) just the kind of thing to not work, or work the same, everywhere and to eventually be the cause of much frustration, especially as the site grows in complexity.
One solution is to use another table inside one tr, in your thead. Althought, this is a totally ugly solution.
You can also place a div above your table using CSS.
Correct table structure is:
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
<thead> will always be on the top and <tfoot> will always be at the bottom.
Using jQuery you can swap <thead> and <tbody> content by:
$(document).ready(function() {
$('#myTrigger').click(function() {
var top = $('thead').html();
var mid = $('tbody').html();
$('thead').html(mid);
$('tbody').html(top);
});
});

Are table headers only for the top row in html?

I always see the th tag only used in the first row of the table. Is there some specific reason why it can't be used to create 'left' headers along the leftmost column. Is this bad form, or is this ok.
Basically, a table with headings on the top row and the leftmost column, with the very top left square being empty.
e.g.
<table>
<tr>
<th><!--empty--></th>
<th>Top 1</th>
<th>Top 2</th></tr>
<tr>
<th>LeftHeader?</th>
<td>data1</td>
<td>data2</td></tr>
</table>
That's valid, however, when using a <thead> it has to be the first row. This is valid:
<table>
<thead>
<tr>
<td>0,0</td><td>1,0</td><td>2,0</td>
</tr>
</thead>
<tr>
<th>0,1</th><th>1,1</th><th>2,1</th>
</tr>
</table>
But this is not:
<table>
<tr>
<td>0,0</td><td>1,0</td><td>2,0</td>
</tr>
<thead>
<tr>
<th>0,1</th><th>1,1</th><th>2,1</th>
</tr>
</thead>
</table>
It's invalid HTML and you can double check that with the w3C markup validation service though before you do you'll have to add a <!DOCTYPE> declaration and the rest of a valid HTML doc.