Nesting a table within a table - Is it possible?
Nesting a table within a table - Is it possible?
gordyr
Posts: 35Questions: 0Answers: 0
Hi,
Firstly I have to say I have fallen in love with DataTables and am now using it for the delivery of all sorts of functionality on a particular site.
However I decided to try something slightly different and use Datatables to render a 'nested comments' interface. Up until this point it has worked perfectly. Datatables renders a table full of 'songs', when I click on one of the songs a new page is loaded with just the individual song, then loads a new table to display a list of comments on that particular song.
However I have created a separate 'replies' table which i use attach replies to each individual comment.
This is best understood by viewing this image:-
http://postimage.org/image/1nziy56s/
So as you can see I have built a flash/JS audio player which has a commenting/replies interface built in. This all works fine, but I am using datatables to also draw a list of the comments beneath the player so that the user can either view the "timed comments" in the player by hovering over an avatar or by scrolling down the list of comments below the player. I have added an external interface call in the flash player so that it refreshes the whole table whenever a new comment/reply is inserted.
What I would like to do (and the part I am struggling with) is how to display the replies within this datatable.
My Tables are set up like so:-
Comments:
commentid, userid, playtime, posttime, body, songid
Replies:
id, userid, commentid, posttime, body
Now I am currently just user server side processing to display the results of the 'comments' table hard filtered by the songid. I am also using a LEFT JOIN on userid to a separate table in order to retrieve the username from the userid. This is all done within my server side code.
So my question really is how can I possibly get the replies to render inline with the actual comments? Obviously I can join the replies table at 'commentid' and then pull this into the retrieved Json... But this is only a starting point....Ultimately I would like to be able to display up to 2 replies on a given comment and provide a 'see more replies' button via jquery to list the rest of the replies. But this sode of things I am fine with. I am jsut having a hard time visualizing where to begin?
Firstly I have to say I have fallen in love with DataTables and am now using it for the delivery of all sorts of functionality on a particular site.
However I decided to try something slightly different and use Datatables to render a 'nested comments' interface. Up until this point it has worked perfectly. Datatables renders a table full of 'songs', when I click on one of the songs a new page is loaded with just the individual song, then loads a new table to display a list of comments on that particular song.
However I have created a separate 'replies' table which i use attach replies to each individual comment.
This is best understood by viewing this image:-
http://postimage.org/image/1nziy56s/
So as you can see I have built a flash/JS audio player which has a commenting/replies interface built in. This all works fine, but I am using datatables to also draw a list of the comments beneath the player so that the user can either view the "timed comments" in the player by hovering over an avatar or by scrolling down the list of comments below the player. I have added an external interface call in the flash player so that it refreshes the whole table whenever a new comment/reply is inserted.
What I would like to do (and the part I am struggling with) is how to display the replies within this datatable.
My Tables are set up like so:-
Comments:
commentid, userid, playtime, posttime, body, songid
Replies:
id, userid, commentid, posttime, body
Now I am currently just user server side processing to display the results of the 'comments' table hard filtered by the songid. I am also using a LEFT JOIN on userid to a separate table in order to retrieve the username from the userid. This is all done within my server side code.
So my question really is how can I possibly get the replies to render inline with the actual comments? Obviously I can join the replies table at 'commentid' and then pull this into the retrieved Json... But this is only a starting point....Ultimately I would like to be able to display up to 2 replies on a given comment and provide a 'see more replies' button via jquery to list the rest of the replies. But this sode of things I am fine with. I am jsut having a hard time visualizing where to begin?
This discussion has been closed.
Replies
To do that, all you need to do is create the HTML tables in the structure you want, just as you would without DataTables. But that might not be what you want?
The closest you can get to having a link between a parent and child rows in a DataTables is using the fnOpen and fnClose API methods. There is a blog post about how to do that here: http://datatables.net/blog/Drill-down_rows
Allan