Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

JQuery closest('tr') won't work


Reply

4 Posts   1739 Views

Avatar
sergieboy

2 March 2012 at 11:43pm Community Member, 33 Posts

I have a table and when I click on a row, the childrows are opened in accordeon style with JQuery.
All works fine. But the only thing is, I want the accordeon to open a the level of the row I clicked.
Therefore, the function closest() is used. But this won't work.
My childtable always opens at the button of the mastertable...

I use the JQuery 1.6.4, so that can not be the problem.

Avatar
martimiz

3 March 2012 at 7:06am Forum Moderator, 1091 Posts

Doesn't closest() travel up the tree? If so, it wouldn't open a child table. Maybe next() would work..

Anyway - not really a SilverStripe question :-)

Avatar
sergieboy

3 March 2012 at 9:12pm Community Member, 33 Posts

100% SS question.
I'm playing around with the JTable in SS. Really cool thing to work with.
All works fine, but there's just one thing I can't get right :
open the child table at the height of the parent table.

http://www.codeproject.com/Articles/277576/AJAX-based-CRUD-tables-using-ASP-NET-MVC-3-and-jTa

I suppose it's the SS framework and the way the page gets rendered. In ASP no problem.

Avatar
martimiz

5 March 2012 at 1:19am Forum Moderator, 1091 Posts

Well, you didn't say that, did you? : -) You just said you had a table (somewhere), you click a row (= tr in my book) and closest() doesn't get you that same row (tr) - which it wouldn't, when you're clicking the row itself...

I suppose you're referring to something like this (from the jTable demo's):

$img.click(function () {
   $('#StudentTableContainer').jtable('openChildTable',
      $img.closest('tr'),
      { ...

clicking this image inside a cell should definitelyget you the encompassing tr. Still: I don't see how this is a SilverStripe issue, unless of course you are trying to use this in the backend - or using some other interfering javascript on your frontend?