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
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:
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??
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,