Hello,

Yes, IMHO these are very frequent operations to any grid like structure. I
dont know where to write those .. so writing them in this post. 


qx.Proto.addRow = function(newRow) {
        this._rowArr.push(newRow);
        
        var rowArr = this._rowArr;      
        if
(this.hasEventListeners(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED)) {
        var data = { firstRow:rowArr.length - 1, lastRow:rowArr.length - 1,
firstColumn:0, lastColumn:this.getColumnCount() - 1 };
        this.dispatchEvent(new
qx.event.type.DataEvent(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED,
data), true);
        }
        
        this._clearSorting();
};

qx.Proto.removeRow = function() {
        
        var len = this._rowArr.length;
        if (len === 0) {
                return null;
        }
        
        var row = this._rowArr.pop();
        
        var rowArr = this._rowArr;      
        if
(this.hasEventListeners(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED)) {
                len = rowArr.length;
                var rowIndex = (len === 0 ? 0 : len - 1);
        var data = { firstRow:rowIndex, lastRow:rowIndex, firstColumn:0,
lastColumn:this.getColumnCount() - 1 };
        this.dispatchEvent(new
qx.event.type.DataEvent(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED,
data), true);
        }       
        return row; 
};

qx.Proto.deleteRow = function(rowIndex) {
        var len = this._rowArr.length || 0;     
        if (len <= 0 || rowIndex < 0 || rowIndex >= len) {
                return null;
        }
        
        var row = null;
        if ((len == 1 && rowIndex === 0) || (len - 1 == rowIndex)) {
                row = this.removeRow();
        }
        else {
                row = this._rowArr[rowIndex];
                
                var i = rowIndex;
                do {
                        this._rowArr[i] = this._rowArr[i + 1];          
                        i += 1; 
                } while (i < (len - 1));
        }
        row = this.removeRow();

        var rowArr = this._rowArr;
        if
(this.hasEventListeners(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED)) {
        var data = { firstRow:rowIndex, lastRow:rowArr.length - 1,
firstColumn:0, lastColumn:this.getColumnCount() - 1 };
        this.dispatchEvent(new
qx.event.type.DataEvent(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED,
data), true);
        }
        
        return row;     
};

qx.Proto.removeAll = function(rowIndex) {
        //  OR
        // this.setData([]);
        //
        var len = this._rowArr.length || 0;
        
        if (len === 0) {
                return true;
        }
        
        do {
                this._rowArr.pop();
                len -= 1;
        } while (len > 0);

        var rowArr = this._rowArr;      
        if
(this.hasEventListeners(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED)) {
        var data = { firstRow:0, lastRow:rowArr.length - 1, firstColumn:0,
lastColumn:this.getColumnCount() - 1 };
        this.dispatchEvent(new
qx.event.type.DataEvent(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED,
data), true);
        }
        
        this._clearSorting();
                
        return true;    
};


qx.Proto.updateRow = function(rowIndex, newRow) {
        this._rowArr[rowIndex] = newRow;
        
        if 
(this.hasEventListeners(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED))
{
        var data = { firstRow:rowIndex, lastRow:rowIndex, firstColumn:0,
lastColumn:this._rowArr[0].length };
        this.dispatchEvent(new
qx.event.type.DataEvent(qx.ui.table.TableModel.EVENT_TYPE_DATA_CHANGED,
newRow), true);
        }
        
        this._clearSorting();
};

qx.Proto.findFirst = function(colIndex, value, ignoreCase) {
        var len = this._rowArr.length;  
        if (len === 0) {
                return -1;
        }
        var txtToCmp = value;
        if (qx.util.Validation.isValidBoolean(ignoreCase) && ignoreCase === 
true) {
                txtToCmp = txtToCmp.toLowerCase();
        }
                
        var i = 0;
        do {
                if (this._rowArr[i][colIndex] == txtToCmp) {
                        return i;
                }
                i += 1;
                len -= 1;
        } while (len > 0);
        
        return -1;
};

qx.Proto.findLast = function(colIndex, value, ignoreCase) {
        var len = this._rowArr.length;  
        if (len === 0) {
                return -1;
        }
        var txtToCmp = value;
        if (qx.util.Validation.isValidBoolean(ignoreCase) && ignoreCase === 
true) {
                txtToCmp = txtToCmp.toLowerCase();
        }
                
        len -= 1;
        do {
                if (this._rowArr[len][colIndex] == txtToCmp) {
                        return len;
                }
                len -= 1;
        } while (len >= 0);
        
        return -1;
};








dperez wrote:
> 
> Hi Alee,
> 
> Maybe it would be interesting to add this functionality to
> SimpleTableModel, because nearly every user of this class needs to
> add/edit/modify data.
> 
> 
> Alee wrote:
>> 
>> This solved the problem, but the thing is table will be having many rows
>> and there are 4-5 tables in a tab view, so dont you think this will turn
>> down performance. Also, I have subclassed the SimpleTableModel, because I
>> also added few more methods like ..
>> 
>> addRow, DeleteRow, RemoveRow, updateRow. These could also be done without
>> sub-classing but IMHO sub-classing way kept the code more clean.
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Table-UI-Updation-Problem-tf2175737.html#a6020872
Sent from the qooxdoo-devel forum at Nabble.com.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to