刷新点击事件的网格数据 [英] Refreshing grid data on click event

查看:116
本文介绍了刷新点击事件的网格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



代码::

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

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
},
{
字段:名称,
名称:名称,
宽度:20%,
课程:firstname
},
{field:Email,
name:Mail,
width:20%,
classes:名字
}

]
];


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

/ *将新网格附加到div * /
dojo.byId(gridDiv)。appendChild(grid1.domNode);

/ *调用startup()来渲染网格* /
grid1.startup();

//假设我们的网格存储在一个名为myGrid的变量中:
dojo.connect(grid1,onSelectionChanged,grid1,function(){
var items = grid1.selection.getSelected();



//对所选项目执行某些操作
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>

在特定时间点的alert(结果)的输出就像这样::

  [{ID:1,名称:Shantanu,电子邮件:shantanu.tomar@gmail.com },{ID:2,名称:Mayur,电子邮件:mayur.sharma@gmail.com},{ID:3,名称:Rohit},{ ID:4,名称:Jasdeep},{ID:5,名称:Rakesh,电子邮件:rakesh.shukla@gmail.com ,Name:Divyanshu},{ID:8,Names:hello},{ID:9,Names:fine},{ID名称:shivani}] 

alert(store)的输出像:: / p>

  [object Object] 

我正在调用gotoa(),点击内容窗格中的任何位置(暂时将来会放一个按钮或东西),如下所示::

 < div dojoType =dijit.layout.ContentPanetitle =待定活动style =background-image:url('http:// localhost:8080 / 2_8_2012 /images/17.png'); onClick =gotoa();> 

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

解决方案

我是一个新手的dojo,我认为这段代码将帮助你::

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

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


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,
宽度:20%,
类:firstname
},
{field:电子邮件,
名称:邮件,
宽度:20%,
类:firstname
}

]
];


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

/ *将新网格附加到div * /
dojo.byId(gridDiv)。appendChild(grid1.domNode);

/ *调用startup()来渲染网格* /
grid1.startup();

//假设我们的网格存储在一个名为myGrid的变量中:
dojo.connect(grid1,onSelectionChanged,grid1,function(){
var items = grid1.selection.getSelected();



//对所选项目执行某些操作
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)用于更新网格。


I have this code. In here I am retrieving a new set of values via a URL through Jquery Ajax($.get()) on calling a function gotoa() on some click event. I am obtaining the set of values correctly as i am getting right result on alert. But the grid is not updating itself at that moment. When i refresh the whole page then the grid updates. How to update the grid on calling of gotoa() itself. ?

The code ::

<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>

The output of alert(result) at a particular point of time is like this ::

[{"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"}]

And the output of alert(store) is like ::

[object Object]

And i am calling gotoa() on clicking anywhere inside a content pane(for the time being, later on will put a button or something) like this ::

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

How to upgrade grid data ? thanks.

解决方案

I am a newbie to dojo, i think this code will help you::

<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>

use gotoa() for initial loading of grid and gotoa(true) for updating the grid.

这篇关于刷新点击事件的网格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆