Scrolling table with tbody - javascript

I am trying to build a scrollable table from the first answer of this question. Like in the JS here.
In my case my scrollable table needs some tbody inside and when I add them the scroll doesn't work well when it reaches the end.
Example here. At the end of the scroll, there is a space and it should not.
(I need tbody on each tr because I will make from tbody an angular component that will display several tr for row grouping).

This is typo. You have an extra chracter at the end of the second table :
</table>`
After removing it, works fine.
jsbin

Related

Targeting the last PARENT table-row (tr), not the CHILD table-row (tr)

I'm attempting to target the last parent table row within a table that has children table-row elements inside of it. I've tried the below jQuery to target the :last pseudo, however, like expected, it is targeting the absolute last table-row element within the targets parent table.
$('table[id*="dgRegistrantList"]').find('tr:last').addClass('EventRegLastAttendee')
I've put together a jsFiddle with the HTML block I'm attempting to target with the jQuery, I hope it is helpful!
http://jsfiddle.net/jodriscoll/LZA7e/
The Green table-row is the one I would like to target, however, the one highlighted in Red is the obvious one receiving the class.
This system can generate a variant of table rows depending on the users selection prior to this "Step". For a full example of what I'm working with, visit: http://secure.massgeneral.org/event-form (I'm working with Step 2).
Please be aware that the HTML I'm working with is produced by a CMS software that I as the customer, do not have access to changing. Hence the purpose of this jQuery exercise.
If all the parent <tr> elements have the classes BBListOddRowStyle or BBListEvenRowStyle you can do this:
$('table[id*="dgRegistrantList"]').find('tr[class*=RowStyle]:last')
.addClass('EventRegLastAttendee')
DEMO
If not, you can use .children() twice to make sure you target the right ones:
$('table[id*="dgRegistrantList"]').children('tbody')
.children('tr:last').addClass('EventRegLastAttendee')
DEMO
Use this code to target the last row:
$('table[id*="dgRegistrantList"]').find('tr[class^=BBList][class$=RowStyle]:last').addClass('EventRegLastAttendee')
Explanation:
tr //it will look for tr
[class^=BBList] //which class starts with BBList
[class$=RowStyle] //and ends with RowStyle (so we're leaving Odd and Even inside and not recognized)
:last //the last of those element, if you remove it you select all of them
Is .children() what you're looking to do?
$('table[id*="dgRegistrantList"]').children('tr:last').addClass('EventRegLastAttendee');
.children() only goes down one dom level, while .find() will go down as far as it can.
Don't use find. It will look at any depth and it may match unintended subtables. Perhaps it will work for your example, but you don't want to be acquiring a bad habit. Plus, find will be more costly than a targeted approach.
You want a more targeted approach:
var targetTd = $('table[id*="dgRegistrantList"]').children('tbody').children('tr:last').find('table:first').children('tbody').children('td:last');
use this code to target parent tr last row
$('table[id*="dgRegistrantList"]').find('tr[class^=BBList]:last').addClass('EventRegLastAttendee');

Nested_form inside table rows

I'm using nested_form inside one of my Rails forms. I saw you can generate tr 's instead of of div 's using this article https://github.com/ryanb/nested_form/wiki/How-To:-Render-nested-fields-inside-a-table
Where would the javascript go though that they suggest?
window.nestedFormEvents.insertFields = function(content, assoc, link) {
var $tr = $(link).closest('tr');
return $(content).insertBefore($tr);
}
First of all, its not like "you can generate TR 's instead of of DIV". The link says that you can disable inserting DIVs. And you can add the td, tr explicitly. Like in the link they added td and tr in their form.
And sometimes you create forms by javascript and by default those fields are also wrapped with DIV. But you can change the behavior by using that javascript snippet. It will override the corresponding method with this new one.
Let me know if I could clear up your confusions.

IE7 & 8 add unwanted drop shadow to a table inside of another table

I have the follwing jsfiddle http://jsfiddle.net/PrkUW/
There you will find a list-table which has a drop shadow filter applied to it. Inside one of it's rows I have another table, inner-table, which doesn't have any drop shadow declared on it. The problem is that both IE7 and 8 add drop shadow to the inner-table and to it's parent row, and I can't remove it using JS or CSS.
I've tried $('.inner-table').css('filter', '') too but can't get it to work. And as you can see on IE7 the inner-table column's width are a total mess, and borders appear without any declaration.
Does anybody have a suggestion on how to make it look right?
Thanks!
can u check with
$('.inner-table').css('filter', null)
or
using
.removeAttr('class');
jQuery remove attribute

Updating only one cell of a table

I created a 3x3 table. Each column is generated using a function. The function basically returns a "td" element. Else where in the code I trigger an event based on some conditions. Whenever the event is triggered, I want to update one particular cell of the table. None of the cells have ids attached to them.
My question is how can I link up the "td" that I want to be updated with the event?
I have no specific context that refers to this td alone.
If you're not using any other tools like jQuery my approach might be to find the table which I assume you can do with Javascript. Then for each td element in the table inject a class to them that is unique. You could just give them numbers or something easy. Assuming the numbering never changes you now have an easy way to lookup the td elements later in your code without having to keep a reference to the td element you want.
Instead of adding a class you could just get all the td elements in the table and if you knew the 4th element was always the cell you wanted then you could just keep a reference to that td element.
Without using jQuery or anything, you can use DOM selectors such as .childNodes (and iterating till you're satisfied), .lastChild, .firstChild, .parentNode etc.
This link gets you through some examples.
Although, if you are using this a lot, create ID dynamically in JS. Like iterating once through all your table (with .childNodes), assigning an ID (like row1-col2) to every td. It will simplify the rest of your code.
Here is a jsFiddle to show you how with jQuery:
http://jsfiddle.net/HzBFE/

jquery child matching too much?

I am importing a feed into Tumblr and because of the formatting of the site, it shows too many pictures. So to fix that, I thought I would use jquery to remove extra elements.
It turns out that the imported feed uses tables. No worries, I made a jquery call that seemed to work fine on an individual post.
(Pardon the ugly match)
$('.copy div table tbody tr td div table tbody tr td:gt(3)').remove();
This works swimmingly on http://apt.jauderho.com/post/127696762/aaman-lamba-hibiscus
However, going to a page with more than one post, it looks like the second post is being treated as part of the first and hence all the pictures are removed due to the gt(3). My understanding was that using the fragment above, I would be able to iterate on each post leaving only 4 images max per post. See http://apt.jauderho.com/
Can anyone tell me what I'm missing? Thanks.
Try this:
$('.copy div table tbody tr td div table tbody tr').find('td:gt(3)').remove();
The difference from the original is that the find() is executed for every tr that is matched by the first selector. It will remove every td after the 4th td in every matched tr.

Categories