:: Forum >>

Show 'Yes' and 'No' after checkbox problem 2.5.1

I need to display after checkbox a label like 'yes' 'no' instead of 1 0

I found this example that works at well

http://www.activewidgets.com/javascript.forum.18378.2/tips-for-checkbox-template.html

but after I upgrade with new version 2.5.1 I have this error:

this.getContent("box/text").refreshContents is not a function
.../lib/templates/imagetext.js Line 62


How can I solve this problem or there are any workaround to do this?

Thanks in advance
Luca
Tuesday, April 8, 2008
Instead of modifying checkbox template you can just assign a function for the text in this column -

obj.setCellTemplate(new AW.Templates.Checkbox, 1);
obj.setCellText(function(c, r){
    return this.getCellValue(c, r) ? "yes" : "no";
}, 1); // <- column index
Alex (ActiveWidgets)
Tuesday, April 8, 2008
Alex,
thanks for the reply, but my code still not work...

var obj = new AW.UI.Grid;

obj.setCellData([
    [1, "AAA"],
    [0, "BBBB"]
]);

obj.setHeaderText([
    "Boolean", "String"
]);

obj.setRowCount( 2 );
obj.setColumnCount( 2 );

obj.setCellTemplate(new AW.Templates.Checkbox, 0);
obj.setCellText(function(c, r){
    return this.getCellValue(c, r) ? "yes" : "no";
}, 0);

obj.setCellEditable(true);

document.write(obj);


Note: In database I've 1 and 0 (yes/No)

Problems:
1) checks are not initialized correctly
2) If I refresh grid data with obj.setCellData(...) and obj.refresh() the text displayed return 0/1 and does not change more after click

thanks!
Luca
Wednesday, April 9, 2008
>> 1) checks are not initialized correctly

It will initialize correctly if you use true and false instead of 0 and 1. If you want to keep using 0 and 1 you should add cellValue function which converts them to true/false -

obj.setCellValue(function(c, r){
    return this.getCellData(c, r) ? true : false;
}, 0);


>> 2)

when you call setCellData() - cellText and cellValue will be replaced with default values, so you have to assign those functions again.
Alex (ActiveWidgets)
Wednesday, April 9, 2008
Alex, Thanks a lot for the response,
just an other question:
is there a way to disable edit except for Space and Enter that works as mouseclick?
Luca
Thursday, April 10, 2008
You mean disable doubleClick?

obj.onCellDoubleClicked = function(){return 1}
Alex (ActiveWidgets)
Thursday, April 10, 2008
Yes but also to filter keypress: enable only "space" key for the column.

Behaviour: if I press "space" the check became checked, if I press it again became unchecked. All others keys are disabled.

It's possible?
Thanks
Luca
Friday, April 11, 2008
If just want to disable editing for this column -

obj.setCellEditing(false, 0); // column index
Alex (ActiveWidgets)
Friday, April 11, 2008

This topic is archived.


Back to support forum

Forum search