3.2.0

Delete rows that are not checked

Hi,

What i'm trying to do, is create a grid with the first column as checkboxes.

I want the user to select the checkboxes of the rows that the user does NOT want to delete and delete the rows that are NOT checked.

I created my grid and set the first row to a checkbox"

obj.setCellTemplate(new AW.Templates.Checkbox, 0);

//set the values to false
obj.setCellValue(false, 0);
// toggle it to yes and no
obj.setCellText(function(col, row){return this.getCellValue(col, row) ? "yes" : "no"}, 0);
// Then write it.
document.write(obj);

I then created a getChecked method to delete the rows (I would add this function to a button):

function getChecked() {
var knt = 0;
knt = obj.getRowCount();

for(var i= knt - 1; i > -1; i--) {
if(!obj.getCellValue(0,i)) {
obj.deleteRow(i);
}
}
}

This works great for the first time, but the second time i try it, the
obj.getRowCount(); does not alway gives the right knt and decrements to 0 and for the rows, the checkbox values are are not setting to the proper checked and unchecked state.

Does anyone know how to fix this or is there a better way to do this?

Thanks for your time.



DP
July 6,
I figured it out.

If you delete the rows, the rows still have the original index. So the first time you would just delete by the row count. Subsequent attempts you need to get the indexes by obj.getRowIndices();.

Here is my test code below.

function getChecked() {
var knt = 0;
var value = obj.getRowIndices();
if (value.length == 0){
knt = obj.getRowCount();
} else {
knt = value.length;
}
for(var i= knt - 1; i > -1; i--) {
if (value.length != 0 ){
if(!obj.getCellValue(0,value[i]) ) {
obj.deleteRow(value[i]);
}
} else {
if(!obj.getCellValue(0,i)) {
obj.deleteRow(i);
}
}
}
}
DP
July 7,

This topic is archived.

See also:


Back to support forum