3.0.0

Sorting in grid with numeric, text and checkboxes

//code for displaying normal text/numeric values
obj.setCellData(
function(col, row) {
if(data[row][col]==0) {
return '';
}
else {
return data[row][col];
}
});

//code for displaying checkboxes values
obj.setCellValue(
function(col, row) {
//since checkboxes begin with the word 'Allow'
if (columns[col].indexOf('Allow') > -1) {
if (data[row][col]=='T')
return true;
else
return false;
}
//for normal text/numeric values
else {
if(data[row][col]==0) {
return '';
}
else {
return data[row][col];
}
}
});


These are the problems I'm facing:
1. if I don't include obj.setCellValue, then checkboxes don't work correctly, but text and numeric sorting are fine
2. Once I include obj.setCellValue, numeric values are sorted like text e.g 2, 20, 5, 55

Can you tell me how to get sorting with different data types to work correctly.

Thanks.
AI
January 12,
The grid is sorted according to the cellValue properties, which are calculated from the cellText or cellData by the cellFormat objects. When you assign your own function to cellValue - you overwrite the default ones and break the sorting. In your case you should assign the cellValue function only to the column where you have checkboxes -

obj.setCellValue(valueFunction, columnIndex);
Alex (ActiveWidgets)
January 13,
Alex, I made changes so that the setCellData gets called only for non-checkbox columns and setCellValue only for checkbox columns.
Now I find that when the grid has numeric and text columns the sorting works fine. However, for grids that involve checkboxes and text/numeric, the sorting is ok for the checkboxes but not for the numeric/text.

This is how I changed the code:

//setCellData is used for displaying normal text (not checkboxes)
for (var i = 0; i < columns.length; i++) {
if (columns[i].indexOf('Allow') > -1) { //checkboxes start w/ 'Allow'
;
}
else {
obj.setCellData(
function(col, row) {
if(data[row][col]==0) {
return '';
}
else {
return data[row][col];
}
});
} //else
} //for

//setCellValue is used for displaying checkboxes
for (var i = 0; i < columns.length; i++) {
if (columns[i].indexOf('Allow') > -1) {
obj.setCellValue(
function(col, row) {
if (columns[col].indexOf('Allow') > -1) {
if (data[row][col]=='T')
return true;
else
return false;
}
});
} //if
} //for


AY
January 14,
Looks like you are still missing column index in setCellValue function assignment -

});
} //if
} //for

Should be -

}, i);
} //if
} //for

Alex (ActiveWidgets)
January 14,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.