Insert new row after a specific row in $.ajax call

Insert new row after a specific row in $.ajax call

I need to insert several rows of data into a particular place from the success function of an $.ajax call to a PHP database query.

What follows is the result of a suggestion at StackOverflow and some of my own testing. Currently this only inserts the new table into the space of a single cell immediately after the target row.

  1. function GetActorsForSelectedMovie(movieID) {
  2.    // $.ajax call gets rows from php script

  3.    var row = $('#tblMovieList tbody tr').find('td input.chkDeleteMovie[value="' + movieID + '"]').parent().parent();
  4.    var newRowTable = $('<table id="tblActorsForMovie"></table>');

  5.    //$.each(data, function (index, element) {
  6.    newRowTable.append('<td width="113px"></td><td>actorID: 12, name: Some Actor</td>');
  7.    //});

  8.    row.after(newRowTable.wrap('<tr id="actorsForMovie" /><td colspan="10" />'));
  9. }

What I need to do is insert a row that contains the json data from the php script after the row that has a checkbox with a value set to a specific movie ID.

As I said, the code above inserts a table after the target row, but what gets inserted is just a table, not a table wrapped in a set of <tr><td> tags to work with the "parent" row. You'll see what I mean if you follow the jsFiddle link at the bottom of this post.

The final structure of the row that is to be inserted should look something like this:

  1. <tr id="actorsForMovie">
  2.     <td colspan="10"> <!-- There are 10 rows in the "parent" table -->
  3.         <table>
  4.             <tr>
  5.                 <td>
  6.                     [actor data]
  7.                 </td>
  8.             </tr>
  9.             <tr>
  10.                 <td>
  11.                     [actor data]
  12.                 </td>
  13.             </tr>
  14.             ... etc for additional rows/actors
  15.         </table>
  16.     </td>
  17. </tr>

I have created a jsFiddle for anyone to take a crack at helping me figure this out. No matter what I've tried, the inserted table 1) Never gets wrapped in the and tags to make it work with the "parent" table, and 2) the inserted table always only gets put in the area of the first cell in the rest of the table.

____________________________________
f u cn rd ths u cn gt a gd jb n prgrmmng
    • Topic Participants

    • mark