how to check the checkbox automatically when i click on a row in enhanced grid in dojo using indirect selection

StackOverflow https://stackoverflow.com/questions/19151507

Question

here i am using indirect selection in enhanced grid,when i clicked on check box it is working fine....now i want to click the row or any cell in the grid by that the checkbox should get selected....please help in this.....tried rowclick,cellclick but nothing gone right...please help.........

{
        require([ "dojo/_base/lang", "dojox/grid/EnhancedGrid",
                "dojox/grid/enhanced/plugins/Search",
                "dojox/grid/enhanced/plugins/Filter",
                "dojox/grid/enhanced/plugins/Pagination",
                "dojo/data/ItemFileWriteStore", "dojo/store/JsonRest",
                "dijit/form/Button", "dojo/_base/xhr", "dojo/dom",
                "dojo/dom-construct", "dojo/json", "dojo/on",
                "dojox/grid/cells/dijit", "dojo/domReady!" ],
        function(lang, EnhancedGrid, Search, Filter, Pagination,
                ItemFileWriteStore, JsonRestStore, Button, xhr, dom,
                domConst, JSON, on) {
            xhr.get({
                url : "http:myaddress:8080/GridSampleDojoExample/string",
                handleAs : "json",
                load : function(dataa) {

                    var mydata = dataa;
                    alert(JSON.stringify(dataa));

                    var yourStore = new dojo.data.ItemFileWriteStore({
                        data : {
                            identifier : "sno",
                            /* items: mydata.aa */
                            items : mydata
                        }
                    });

                    grid = new EnhancedGrid({
                        id : 'grid',
                        store : yourStore,
                        structure : layout,
                        rowSelector : '20px',
                        plugins : {
                            search : true,
                            indirectSelection: {
                                headerSelector:true, 
                                width:"40px",
                                styles:"text-align: center;"

                                },
                            pagination : {
                                pageSizes : [ "50", "100"],
                                description : true,
                                sizeSwitch : true,
                                pageStepper : true,
                                gotoButton : true,
                                maxPageStep : 2,
                                position : "bottom",
                                defaultPageSize: 50
                            },
                            filter : {

                                closeFilterbarButton : true,
                                ruleCount : 5,
                                itemsName : "rows"
                            }
                        }
                    });
                    grid.placeAt("myGrid");
                    grid.startup();



                }
            });



        /*  grid.on("RowClick", function (event) {
                  for (var i=0; i<store._arrayOfAllItems.length; i++) {
                    if (grid.getItem(i)) {
                      if (grid.getItem(i).check[0]) {
                        alert("clicked");
                      } else {
                        alert("row is not checked, do something else");
                      }
                    }
                  }
                }  */

            var id = Math.floor((Math.random()*100000)+100000);
            var addbutton = new Button({
                onClick : function() {
                    id++;

                    grid.store.newItem({
                        sno : id,
                        sname : 'san',
                        salary : '25000',
                        designation:'Product Engineer',
                        city:'Madras',
                        firstname:'asr',
                        lastname:'poi',
                        anualincome:'12345678'


                    });

                    var stringdata=id+"#san#25000#Product Engineer#Madras#asr#poi#12345678";

                    require(    [ "dojo/_base/xhr" ],
                                    function(xhr) {     xhr.get({
                                                        url : "http://localhost:8080/GridSampleDojoExample/UpdateServlet",
                                                                        content : {
                                                                            name : stringdata
                                                                        },
                                                                        load : function(
                                                                                result) {
                                                                            alert("The message is: "
                                                                                    + result);
                                                                        }
                                                                    });

                                                        });
                                                store.save();
                                                grid.render();

                                }




            }, "addRow");


            var removebutton = new Button(
                    {
                        onClick : function() {
                            var items = grid.selection.getSelected();


                            if (items.length) {

                                dojo
                                        .forEach(
                                                items,
                                                function(selectedItem) {

                                                    if (selectedItem !== null) {


                                                        var stringdata = grid.store
                                                                .getValue(
                                                                        selectedItem,
                                                                        "sno");






                                                        require(
                                                                [ "dojo/_base/xhr" ],
                                                                function(
                                                                        xhr) {

                                                                    xhr.get({
                                                                                // The URL to request
                                                                                url : "http://localhost:8080/GridSampleDojoExample/DeleteServlet",
                                                                                content : {
                                                                                    name : stringdata
                                                                                },
                                                                                load : function(
                                                                                        result) {
                                                                                    alert("The message is: "
                                                                                            + result);
                                                                                }
                                                                            });

                                                                });


                                                        grid.store.deleteItem(selectedItem);

                                                    }
                                                });
                                store.save();
                                grid.render();                                          

                            }

                        }
                    }, "removeRow");



            var updatebutton = new Button(
                    {
                        onClick : function() {
                            var items = grid.selection.getSelected();

                            if (items.length) {

                                dojo
                                        .forEach(
                                                items,
                                                function(selectedItem) {

                                                    if (selectedItem !== null) {


                                                        var stringdata = grid.store
                                                                .getValue(
                                                                        selectedItem,
                                                                        "sno");
                                                        stringdata = stringdata
                                                                + "#"
                                                                + grid.store
                                                                        .getValue(
                                                                                selectedItem,
                                                                                "sname");

                                                        stringdata = stringdata
                                                                + "#"
                                                                + grid.store
                                                                        .getValue(
                                                                                selectedItem,
                                                                                "salary");
                                                        stringdata = stringdata
                                                                + "#"
                                                                + grid.store
                                                                        .getValue(
                                                                                selectedItem,
                                                                                "designation");
                                                        stringdata = stringdata
                                                                + "#"
                                                                + grid.store
                                                                        .getValue(
                                                                                selectedItem,
                                                                                "city");
                                                        stringdata = stringdata
                                                                + "#"
                                                                + grid.store
                                                                        .getValue(
                                                                                selectedItem,
                                                                                "firstname");
                                                        stringdata = stringdata
                                                                + "#"
                                                                + grid.store
                                                                        .getValue(
                                                                                selectedItem,
                                                                                "lastname");
                                                        stringdata = stringdata
                                                                + "#"
                                                                + grid.store
                                                                        .getValue(
                                                                                selectedItem,
                                                                                "anualincome");



                                                        require(
                                                                [ "dojo/_base/xhr" ],
                                                                function(
                                                                        xhr) {

                                                                    xhr.get({
                                                                                // The URL to request
                                                                                url : "http://localhost:8080/GridSampleDojoExample/UpdateServlet",
                                                                                content : {
                                                                                    name : stringdata
                                                                                },
                                                                                load : function(
                                                                                        result) {
                                                                                    alert("The message is: "
                                                                                            + result);
                                                                                }
                                                                            });

                                                                });
                                                    }
                                            });
                            }

                        }
                    }, "updateRow");


            /* dojo.connect(grid, "onCellClick", function (e) {
                var colField = e.cell.field; // field name
                var rowIndex = e.rowIndex; // row index
                alert(colField+rowIndex);
            });

             */
            /*  grid.on("RowClick", function(evt){
                    var idx = evt.rowIndex,
                        rowData = grid.getItem(idx);
                    alert(rowData);
                }, true);

*/

            /*  store.onNew = function( new_item ) {
                    var rowIndex = new_item._0;                
                    window.setTimeout(function() {
                        grid.focus.setFocusIndex( rowIndex, 0 );
                        grid.edit.setEditCell( grid.focus.cell, rowIndex );
                    },10);    

                }; */

        });

}

Was it helpful?

Solution

using selector plugin in grid plugin....i solved my problem

selector: { 

  cell: false, 

  col: false 
}, 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top