1

在这里,我在增强网格中使用间接选择,当我单击复选框时它工作正常....现在我想单击网格中的行或任何单元格,复选框应该被选中....请帮助在这个.....尝试了rowclick,cellclick但没有任何问题......请帮助......

{
        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);    

                }; */

        });

}

4

1 回答 1

1

在网格插件中使用选择器插件....我解决了我的问题

selector: { 

  cell: false, 

  col: false 
}, 
于 2013-10-03T09:51:08.517 回答