当我使用间接选择单击dojo中的增强网格中的行时,如何自动选中复选框

时间:2013-10-03 05:32:43

标签: javascript dojo dojox.grid.datagrid dojox.grid

这里我在增强网格中使用间接选择,当我点击复选框它工作正常....现在我想点击网格中的行或任何单元格,复选框应该被选中... 。请帮助这个.....尝试了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);    

                }; */

        });

}

1 个答案:

答案 0 :(得分:1)

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

selector: { 

  cell: false, 

  col: false 
},