Raimundo Patillas
Raimundo Patillas

Reputation: 21

Remove row from TableContainer

I'm programmatically developing a TableContainer. When I push a button, it adds dynamically a new row in this TableContent. This new row has a button to delete it if I push it.

HTML

<div id="formTableContent" class="tblForm"></div>

Javascript

var _tableForm = null;
_onLoad : function() {
    this._tableForm  = new dojox.layout.TableContainer(
        {
            cols : 3,
            customClass :"labelsAndValues",       
            "labelWidth" : "100"
        }, dojo.byId("formTableContent")
    );

   this._tableForm.startup();
},


// This method add a new row in TableContainer
_createRow : function() {
    var txtBox1 = new dijit.form.TextBox({ label : "textlabel1" });
    var txtBox2 = new dijit.form.TextBox({ label : "textlabel2" });
    var btnDelete = new dijit.form.Button({ label : "Delete", spanLabel : true, iconClass : "removeIcon" });
      dojo.connect(btnDelete, "onClick", this, function(evt) {
          var row = evt.path[5];
          row.parentNode.removeChild(row);
      });

    this._tableForm.addChild(txtBox1);
    this._tableForm.addChild(txtBox2);
    this._tableForm.addChild(btnDelete);
    this._tableForm._initialized = false;
    this._tableForm._started = false;
    this._tableForm.startup();
},

Image Example

In the event 'onClick' I tried do this:

dojo.connect(btnDelete, "onClick", this, function(evt){
    var row = evt.path[5];
    row.parentNode.removeChild(row);
});

It deteles the row, but when I add a new row, in the TableContainer appear the row deleted and the new row added.

Upvotes: 2

Views: 239

Answers (1)

bajji
bajji

Reputation: 1291

I know it's an old post but this might helps others. TableContainer has a method removeChild(child) and if you use this, the row will be deleted and it will not reappear when you add a new row.

Upvotes: 1

Related Questions