3.2.0

Insert and Delete Highlighted Row

I am really struggling to get the grid to delete the highlighted row and complete remove all the cell text,data,value... and leave the grid in tack working correctly after the row has been removed...

I have tried using Carlos's example of delete row from his recent post as follows

delRow.onControlClicked = function(row) {
var SortedIndices=[]; 
for (i=0;i<CellText.length;i++){ SortedIndices.push(i) } 
   
 obj.onHeaderClicked         = function(event, index){
 window.setTimeout(function(){
 SortedIndices = obj.getRowIndices();
 },30);
 }
        
  var startrow = obj.getSelectedRows();  
    if( Number(startrow)>-1){
    for (i=SortedIndices.length-1;i>=0;i--){ 
if(SortedIndices[i] == startrow){ SortedIndices.splice(i, 1);  break}
}
 obj.setRowCount(obj.getRowCount()-1);
  obj.setRowIndices(SortedIndices);
    }  
 }


1. This deletes the highlighted row but if you add the row back the cell text,value,data re-appears.
2. You cannot then selected the rows below.. or click in the grid in appears to be locked


I have almost achieve it by looping down the grid loading the information into an array, clearing the grid and putting back the information back less the highlighted row as follows:

delRow.onControlClicked = function(row) {
        
            if(obj.getSelectedRows()=='') {alert('WARNING! You must select a row to delete');return false;}
            var insertindex=obj.getSelectedRows([0]); 
            if(obj.getCellValue(19,insertindex)=='true' || obj.getCellValue(21,insertindex)=='true' || obj.getCellValue(22,insertindex)=='true'){alert('WARNING! You can not delete a row that has been completed, backordered or invoiced'); return false;}
            if(obj.getCellValue(19,insertindex)==true){alert('WARNING! You can not delete a row that has been completed, backordered or invoiced'); return false;}
            if(obj.getCellValue(21,insertindex)==true){alert('WARNING! You can not delete a row that has been completed, backordered or invoiced'); return false;}
            if(obj.getCellValue(22,insertindex)==true){alert('WARNING! You can not delete a row that has been completed, backordered or invoiced'); return false;}
                        var Row = 0;
                        var gridArray = new Array();
                        for(i=0;i<=obj.getRowCount();i++)
                        {
                            //alert(i+" "+insertindex);
                            if(i!=insertindex)
                            {
                            //alert('here');
                            gridArray[Row] = new Array();
                            gridArray[Row][1] = obj.getCellText(0,i);
                            gridArray[Row][2] = obj.getCellText(1,i);
                            gridArray[Row][3] = obj.getCellValue(2,i);
                            gridArray[Row][4] = obj.getCellValue(3,i);
                            gridArray[Row][5] = obj.getCellValue(4,i);
                            gridArray[Row][6] = obj.getCellText(5,i);
                            gridArray[Row][7] = obj.getCellText(6,i);
                            gridArray[Row][8] = obj.getCellText(7,i);
                            gridArray[Row][9] = obj.getCellText(20,i);
                            gridArray[Row][10] = obj.getCellText(24,i);
                            gridArray[Row][11] = obj.getCellValue(19,i);
                            gridArray[Row][12] = obj.getCellValue(21,i);
                            gridArray[Row][13] = obj.getCellValue(22,i);
                            Row++
                            }
                        }
                        
                        //for(i=0;i<gridArray.length;i++) {
                        //document.write(gridArray[0][6]);
                        
                        //}
                        
                        //Script for the DocumentLoader Body Information
                        obj.setCellText([]);
                        obj.refresh();
                        var cellLen = gridArray.length -1;
                        
                        for(i=0;i<=gridArray.length;i++) {
                            
                            
                                obj.setCellText(gridArray[i][1],0,i);//SKU
                                obj.setCellText(gridArray[i][2],1,i);//Line Description
                                obj.setCellText(gridArray[i][3],2,i);//Unit Price
                                obj.setCellValue(gridArray[i][3],2,i);//Unit Price
                                obj.setCellData(gridArray[i][3],2,i);//Unit Price
                                obj.setCellData(gridArray[i][4],3,i);//Qty				
                                obj.setCellData(gridArray[i][5],4,i);//Discount
                                obj.setCellData(gridArray[i][6],5,i);//Line Nett
                                obj.setCellText(gridArray[i][7],6,i);//Centre				
                                obj.setCellText(gridArray[i][8],7,i);//VAT				
                                obj.setCellText(gridArray[i][9],20,i);//InStk
                                obj.setCellText(gridArray[i][10],24,i);//Location
                                obj.setCellValue(gridArray[i][11],19,i);//Complete
                                obj.setCellValue(gridArray[i][12],21,i);//Backorder
                                obj.setCellValue(gridArray[i][13],22,i);//Invoiced
                                if(gridArray[i][13]=='true'){for(x=0;x<30;x++){obj.setCellEditable(false, x, i);obj.getRowTemplate(i).setStyle("background","#81BEF7");}}
                                if(gridArray[i][11]=='true'){for(x=0;x<30;x++){obj.setCellEditable(false, x, i);}}
                                obj.setRowCount(cellLen);  
                                
                                obj.refresh();
                                
                                obj.setSelectedRows([insertindex]);
                                obj.setCurrentRow(insertindex);
                                obj.setSelectedColumns([0]);
                                obj.setCurrentColumn(0);
                                
                                try{obj.setSelectedRows([insertindex]);}catch(e){;}
                                gGirdId = obj.getId();
                                try{setTimeout("document.getElementById(gGirdId).focus();",500);}catch(e){;} 
                                
                            
                            }
                            
                            
        
                            
                            
                            
                        }



Their has to be an easier solution... because as you can I see I have a complicated grid with a mixture of cell values & cell text that each have to be loaded back correctly...


Alex we need

1. A function to delete the highlighted row and removes all the cells data from the highlighted row and deals with all the background stuff like the row indices etc so the row simple deletes... and the grid functions as you would expect after deleting a row. it's then up to us to update external databases etc the row delete is simply on screen and I understand that it wont update the data behind it.

1. A function the inserts a highlighted row... as above..

Surely this can achieved... or am I missing something

Carlos,,, I am sure that you can resolved the issue with you function... I suspect that I am doing something wrong please advice??
Jez (TTS)
December 22,
Jez, Not sure if is possible that way ( I will try) , but as a first approach , if the array suffers changes in length, the correct implementation includes a grid data reload ( or playing with a cloned array) , that should involve Models clearing.
I mean same as inserting new columns in this thread:

http://www.activewidgets.com/javascript.forum.21740.3/unable-to-add-insert-a.html

Although I remember a similar post for rows that could also helps.
Will try to do some research and testing.
HTH
Carlos
December 22,
Sorry , no clearModel is needed in case of rows ( while columns remain fixed), but still data reloading to renew the row Indices ( as if no row where inserted or deleted).
Interesting.. how to solve this
Carlos
December 22,
( Not Related) Jez, I recently read and old post ("your's", & closed) due to a similar issue I encounter, and found a possible reason ( request inside a loop). Dindn't test it, but worth to try ( if you allready have it unsolved)
http://www.activewidgets.com/javascript.forum.25601.8/iterrate-http-request-problem.html

print.onControlClicked = function printReport() {
 for(var i=0;i<obj.getRowCount();i++) { 
   var c1 = obj.getCellText(0, obj.getRowPosition(i) );
   var c2 = obj.getCellText(1, obj.getRowPosition(i) );
   var c3 = obj.getCellText(2, obj.getRowPosition(i) ); 
}  
 var a = new AW.HTTP.Request;  
   a.setParameter("C1", c1); 
   a.setParameter("C2", c2); 
   a.setParameter("C3", c3); 
   a.setURL("HTTPResponse.php"); 
   a.setRequestMethod("POST"); 
   a.request(); 
//   pause(100); // pause removed if request out of loop
}
Carlos
December 22,
Carlos... hows tricks??

Setting the a.setAsync(false); cured that problem... I have had no further issues when reiterating down a grid and sending the HTTP Request, each row sends in the correct order with setAsync(false);

Thanks for your input

...

Back to my post...

I have just tried using the obj.deleteRow() and obj.addRow() and remember now why I had to write my own... however you may be able to solve this with your experience with row models and indices ect

Ok...

obj.deleteRow() appears to work and if I add the highlighted row index it deletes the selected row no problem.. as follows:
obj.deleteRow(obj.getCurrentRow());


However it breaks if I then use obj.addRow(); and subsequently then delete and add rows at ramdam, it breaks the Grid in terms of lots of rows become highlighted.... and you cannot edit them ect...

It this because of the row indices going out of sync???

Maybe you can replicate this and come up with the solution...

Jez (TTS)
December 22,
Jez, I think the 'small' mistake resides in a variable declaration.
var SortedIndices=[];
you put this line inside a function declaring it private, and should be 'public' to be accesed also from the addRow routine , try to move it , and let us know if that works.
HTH
Carlos
December 23,
I have moved this outside the function and it still fails it now removed all lines in the grid???

var SortedIndices=[]; 		
        
        var delRow = new AW.UI.Button;
        delRow.setStyle("width","60px");		
        delRow.setControlText("Delete");
        delRow.setControlTooltip('<?Php print tooltip($_SESSION['Company'],1550,$linkPyramid); ?>');
        delRow.onControlClicked = function(row) {

for (i=0;i<CellText.length;i++){ SortedIndices.push(i) } 
   
 obj.onHeaderClicked         = function(event, index){
 window.setTimeout(function(){
 SortedIndices = obj.getRowIndices();
 },30);
 }
        
  var startrow = obj.getSelectedRows();  
    if( Number(startrow)>-1){
    for (i=SortedIndices.length-1;i>=0;i--){ 
if(SortedIndices[i] == startrow){ SortedIndices.splice(i, 1);  break}
}
 obj.setRowCount(obj.getRowCount()-1);
  obj.setRowIndices(SortedIndices);
    }  
 }
Jez (TTS)
February 12,

var SortedIndices=[];         

for (i=0;i<obj.getRowCount();i++){ SortedIndices.push(i) } 

 obj.onHeaderClicked         = function(event, index){
 window.setTimeout(function(){
 SortedIndices = obj.getRowIndices();
 },30);
 }
        
        var delRow = new AW.UI.Button;
        delRow.setStyle("width","60px");        
        delRow.setControlText("Delete");
  //      delRow.setControlTooltip('print tooltip($_SESSION['Company'],1550,$linkPyramid); ?>');
  
  
        delRow.onControlClicked = function(row) {
  var startrow = obj.getSelectedRows();  
    if( Number(startrow)>-1){
    for (i=SortedIndices.length-1;i>=0;i--){ 
if(SortedIndices[i] == startrow){ SortedIndices.splice(i, 1);  break}
}
 obj.setRowCount(obj.getRowCount()-1);
  obj.setRowIndices(SortedIndices);
    }  
 }
February 12,

This topic is archived.

See also:


Back to support forum