Select to view content in your preferred language

Checkbox in a datagrid

3657
4
Jump to solution
05-30-2012 08:22 AM
AllisonAnderson
Occasional Contributor
I have a datagrid with a field that's a link to an image service.  I want to use a formatter for the field that would be a checkbox that would turn the raster on or off.  Here's what I have so far:
    function makeRasterButton(id){            var rBtn = "<div><button dojoType='dijit.form.ToggleButton' data-dojo-props=iconClass:'dijitCheckBoxIcon' onChange=\"addRaster('"+id+"')\"></div>";              //var rBtn = "<div dojoType='dijit.form.Button';'><img src='images/page.png'";         //rBtn = rBtn + " width='18' height='18'";         //rBtn = rBtn + " onClick=\"addRaster('"+id+"')\"></div>";                return rBtn }     function addRaster(id){         var params = new esri.layers.ImageServiceParameters();           params.noData = 0;                  var rasterUrl = id;        var raster = new esri.layers.ArcGISImageServiceLayer(rasterUrl,{          imageServiceParameters: params, "opacity": .70        })                 map.addLayer(raster); }


I've gotten a simple button to work (which you can see commented out), but I would really like a check box, or toggle button.  Where does the iconClass come from?  I guess I'm not understanding how to call the 'dijitCheckBoxIcon' and have it show up correctly in the datagrid.

Yes, I still need to write the code for turning the raster off...
0 Kudos
1 Solution

Accepted Solutions
JamesS1
Regular Contributor
With the formatter, you would return a CheckBox:

return new dijit.form.CheckBox({
        id: "checkBox",
        name: "checkBox",
        value: "Check Me",
        checked: false,
        onChange: function () { alert('onChange called'); } }
    });

View solution in original post

0 Kudos
4 Replies
JamesS1
Regular Contributor
With the formatter, you would return a CheckBox:

return new dijit.form.CheckBox({
        id: "checkBox",
        name: "checkBox",
        value: "Check Me",
        checked: false,
        onChange: function () { alert('onChange called'); } }
    });
0 Kudos
AllisonAnderson
Occasional Contributor
It worked!  Thanks!

I had to tweak it a tiny bit - the id value was giving me this: Error: Tried to register widget with id==checkBox but that id is already registered

Once I removed the id:"checkBox" it worked.

So my final code was
    function makeRasterButton(id){
    
      return new dijit.form.CheckBox({name:"checkBox", value:"On/Off", checked:false, onChange:addRaster(id)});
}


Thanks again, I've been banging my head against a wall for a while with this one...
0 Kudos
JamesS1
Regular Contributor
You're welcome. You may want the id back in there if you ever want to get the checkbox using dojo.byId. I just made the id: "checkBox" for simplicity. When writing modules I tend to set the ids to the module name, to make sure they are unique. ex: id: 'cbxModule_SearchFilter_Option1'.
0 Kudos
AllisonAnderson
Occasional Contributor
So, I'm having a difficult time adding the id back in, which I need so that I can check to see if the checkbox is checked or not.  My issue is that somehow the checkbox is being declared three times, thus I get the error: Tried to register widget with id==checkBox but that id is already registered

If I put an alert to see what the id is, I get three alerts for each check box.  Any clue as to why I might get this behavior?
0 Kudos