3.0.5

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
April 8,
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)
April 8,
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
April 9,
>> 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)
April 9,
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
April 10,
You mean disable doubleClick?

obj.onCellDoubleClicked = function(){return 1}
Alex (ActiveWidgets)
April 10,
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
April 11,
If just want to disable editing for this column -

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

This topic is archived.

See also:


Back to support forum