刷新点击事件的网格数据

时间:2012-03-15 09:10:45

标签: javascript jquery datagrid dojox.grid.datagrid

我有这个代码。在这里,我通过Jquery Ajax($。get())在一些click事件上调用函数gotoa()时通过URL检索一组新值。我正确地获得了一组值,因为我在警报上得到了正确的结果。但是网格当时并没有自我更新。当我刷新整个页面然后网格更新。如何在调用gotoa()本身时更新网格。 ?

代码::

<script type="text/javascript">
function gotoa(){
    $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp?random=" + new Date().getTime(), function(result){

            alert(result);
            var storedata={
                identifier:"ID",
                label:"name",
                items:result
        };


    var store = new dojo.data.ItemFileWriteStore({data: storedata});
    alert(store);
    //var gridh = dijit.byId("gridDiv");
    //gridh.setStore(store);


        var gridStructure =[[

                          { field: "ID",
                                name: "ID_Emp",
                                width: "20%",
                                classes:"firstname"
                          },
                          {
                              field: "Names",
                              name: "Name",
                              width: "20%",
                              classes: "firstname"
                          },
                          { field: "Email",
                                name: "Mail",
                                width: "20%",
                                classes:"firstname"
                          }

                    ]
              ];


         var grid1 = new dojox.grid.DataGrid({
                id: 'grid2',
                store: store,
                structure: gridStructure,
                rowSelector: '30px',
                selectionMode: "single",
                autoHeight:true,
                columnReordering:true},
              document.createElement('div'));

            /*append the new grid to the div*/
            dojo.byId("gridDiv").appendChild(grid1.domNode);

            /*Call startup() to render the grid*/
            grid1.startup();

         // assuming our grid is stored in a variable called "myGrid":
            dojo.connect(grid1, "onSelectionChanged", grid1, function(){
                var items = grid1.selection.getSelected();



            //  do something with the selected items
                dojo.forEach(items, function(item){
                    var v = grid1.store.getValue(item, "Names");

                    function showDialog() {
                        dojo.require('dijit.Tooltip');
                        dijit.byId("terms").show();
                    }
                    //if(name!="Mail")
                    showDialog();
                    }, grid1);

            });


            dojo.connect(grid1, "onCellClick", grid1, function sendmail(){
                var items = grid1.selection.getSelected();

                dojo.forEach(items, function(item){
                    var v1 = grid1.store.getValue(item, "Email");      
                    alert(v1);
                    request.setAttribute("variablemail", v1);
            });

        });


    },"text");

    }

</script>

特定时间点的警报(结果)输出如下::

[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"ID":3,"Names":"Rohit"},{"ID":4,"Names":"Jasdeep"},{"ID":5,"Names":"Rakesh","Email":"rakesh.shukla@gmail.com"},{"ID":6,"Names":"Divyanshu"},{"ID":8,"Names":"hello"},{"ID":9,"Names":"fine"},{"ID":10,"Names":"shivani"}]

alert(store)的输出就像::

[object Object]

我正在点击内容窗格内的任何地方(暂时,稍后会放一个按钮或其他东西)来调用gotoa(),就像这样::

<div dojoType="dijit.layout.ContentPane" title="Pending Activities" style="background-image: url('http://localhost:8080/2_8_2012/images/17.png');" onClick="gotoa();">

如何升级网格数据?谢谢。

1 个答案:

答案 0 :(得分:0)

我是dojo的新手,我认为这段代码可以帮助你::

<script type="text/javascript">
function gotoa(isUpdate){
    $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp?random=" + new Date().getTime(), function(result){

            alert(result);
            var storedata={
                identifier:"ID",
                label:"name",
                items:result
        };


    var store = new dojo.data.ItemFileWriteStore({data: storedata});
    alert(store);
    if (isUpdate) {
       var grid = dojo.byId('grid2');
       grid.setStore(store);
    } else {


        var gridStructure =[[

                          { field: "ID",
                                name: "ID_Emp",
                                width: "20%",
                                classes:"firstname"
                          },
                          {
                              field: "Names",
                              name: "Name",
                              width: "20%",
                              classes: "firstname"
                          },
                          { field: "Email",
                                name: "Mail",
                                width: "20%",
                                classes:"firstname"
                          }

                    ]
              ];


         var grid1 = new dojox.grid.DataGrid({
                id: 'grid2',
                store: store,
                structure: gridStructure,
                rowSelector: '30px',
                selectionMode: "single",
                autoHeight:true,
                columnReordering:true},
              document.createElement('div'));

            /*append the new grid to the div*/
            dojo.byId("gridDiv").appendChild(grid1.domNode);

            /*Call startup() to render the grid*/
            grid1.startup();

         // assuming our grid is stored in a variable called "myGrid":
            dojo.connect(grid1, "onSelectionChanged", grid1, function(){
                var items = grid1.selection.getSelected();



            //  do something with the selected items
                dojo.forEach(items, function(item){
                    var v = grid1.store.getValue(item, "Names");

                    function showDialog() {
                        dojo.require('dijit.Tooltip');
                        dijit.byId("terms").show();
                    }
                    //if(name!="Mail")
                    showDialog();
                    }, grid1);

            });


            dojo.connect(grid1, "onCellClick", grid1, function sendmail(){
                var items = grid1.selection.getSelected();

                dojo.forEach(items, function(item){
                    var v1 = grid1.store.getValue(item, "Email");      
                    alert(v1);
                    request.setAttribute("variablemail", v1);
            });

        });
        }

    });

    }

</script>

使用gotoa()初始加载网格,使用gotoa(true)更新网格。