Skip to content

Instantly share code, notes, and snippets.

@ludo
Created June 18, 2012 18:34
Show Gist options
  • Save ludo/2949901 to your computer and use it in GitHub Desktop.
Save ludo/2949901 to your computer and use it in GitHub Desktop.
Dynamically adding row to a jQuery treeTable
// 1) Removed 'tabindex' (tabindex is something you probably use locally?).
// 2) Removed class="initialized", I don't think it is necessary.
var html_row = '<tr id="node-inserted-1">';
// 3) Removed class ui-draggable. It should be added by jQuery draggable
// plugin.
html_row += '<td><span class="file">Simple element inserted after</span></td>';
html_row += '<td>4 KB</td>';
html_row += '<td>Plain text</td>';
html_row += '</tr>';
var newRow = jQuery(html_row);
//alert(newRow.parents("tr"));
var cquoi = jQuery(newRow[0]);
// 4) Added [0] so that plugin targets correct element. Not very pretty but it
// seems to work.
cquoi.appendBranchTo(jQuery("#node-1")[0]);
// 5) Are you trying to use drag-and-drop as well? The newly added row must be
// made draggable explicitly. I tried the following, which seems to work,
// but it is not very pretty. Perhaps livequery plugin could be used, or
// maybe draggable has some built-in 'live' mechanism.
$("#dnd-example .file, #dnd-example .folder").draggable({
helper: "clone",
opacity: 0.75,
refreshPositions: true,
revert: "invalid",
revertDuration: 300,
scroll: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment