如何在jquery treetable插件中添加子行

时间:2014-10-09 05:40:23

标签: jquery treetable

我想在treetable中添加新行。我用这个链接: firstsecond 但对我没有帮助。

我的代码:

tr = "<tr data-tt-branch='true' style='background-color:#C0C1B7; font-weight: bold; border: 1px solid #95978E;' id=" + result.data[last_index]['codeid'] + " data-tt-id=" + result.data[last_index]['codeid'] + " data-tt-parent-id=" + result.data[last_index]['codeid_parent'] + " >";

            tr += "<td id='column_add_process'><a href='#' style='font-size: 20px; padding-left: 10px; border: 1px solid #95978E;' id="+ result.data[last_index]['codeid'] +" onclick='addChildProcess(" + result.data[last_index]['codeid'] + ")'> + </a></td>";
            tr += "<td id='column_number'>"+ result.data[last_index]['number'] +"</td>";
            tr += "<td id='column_activity'><input type='checkbox' class='cb_click' name='cb_status'  id="+ result.data[last_index]['codeid'] +" /></td>";
            tr += "<td id='column_code_account'><img src='uploads/avatars/"+ avatar +"' /></td>";
            tr += "<td id='column_task_name'>" + result.data[last_index]['task_name'] + "</td>";
            tr += "<td id='column_time_task'>" + result.data[last_index]['time_task'] + "</td>";
            tr += "<td id='column_price_task'>" + result.data[last_index]['price_task'] +"</td>";
            tr += "<td id='column_comments'>" + result.data[last_index]['comments'] + "</td>";
            tr += "<td id='column_file'><a href='#'></a> </td>";
            tr += "<td id='column_operation'><div class='btn-group btn-group-lg'>";
            tr +=       "<input type='button' value='e' name='edit' id=" + result.data[last_index]['codeid'] + " onclick='edit(" + result.data[last_index]['codeid'] + ")' class='btn btn-default'/>";
            tr +=       "<input type='button' value='d' name='delete' id=" + result.data[last_index]['codeid'] + "  onclick='delete_process(" + result.data[last_index]['codeid'] + ")' class='btn btn-default'/>";
            tr += "</div></td>";
            tr += "</tr>";

之后我在树表中添加行

$('#tree_table').prepend(tr);
var newNode = jQuery('#tree_table').treetable("node", row);
jQuery('#tree_table').treetable("expandNode", newNode);

但这不起作用

1 个答案:

答案 0 :(得分:3)

是的!我解决了它

var row = "<tr style='background-color:#C0C1B7; font-weight: bold; border: 1px solid #95978E;' id=" + result.data[last_index]['codeid'] + " data-tt-id=" + result.data[last_index]['codeid'] + " data-tt-parent-id=" + result.data[last_index]['codeid_parent'] + ">";

    var node = $("#tree_table").treetable("node", parent_id);
    $("#tree_table").treetable("loadBranch",node,row);