在dojox.grid.DataGrid中选择特定行时执行事件 [英] Perform an event on selecting a prticular row in dojox.grid.DataGrid

查看:99
本文介绍了在dojox.grid.DataGrid中选择特定行时执行事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的代码,并在dojox.grid.DataGrid网格中向我显示了一组值.现在,我想执行一些事件,例如,当我单击特定的行时,它将重定向我到新的JSP页面.或将打开一个窗口,我可以在其中做某事.怎么做 ?请帮帮我.谢谢.

代码为::

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="MyPackage.PopulateTextbox" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojo/resources/dojo.css";
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dijit/themes/nihilo/nihilo.css";
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojox/grid/resources/Grid.css";
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojox/grid/resources/nihiloGrid.css";

</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojo/dojo.js" djConfig="isDebug: false, parseOnLoad: true"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">

dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.data.ItemFileWriteStore");
</script>
<%
String temp1;
PopulateTextbox obj = new PopulateTextbox();
temp1 = obj.method();
request.setAttribute("variable", temp1); 
%>

<script type="text/javascript">
dojo.ready(function(){
var myVar = <%= request.getAttribute("variable") %>
var storedata={
            identifier:"ID",
            label:"name",
            items: myVar
    };

var store = new dojo.data.ItemFileWriteStore({data: storedata});

    var gridStructure =[[

                      { field: "ID",
                            name: "ID_Emp",
                            width: "40%"
                      },
                      {
                          field: "Names",
                          name: "Name",
                          width: "40%"
                      }

                ]
          ];


     var grid = new dojox.grid.DataGrid({
            id: 'grid',
            store: store,
            structure: gridStructure,
            },
          document.createElement('div'));

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

        /*Call startup() to render the grid*/
        grid.startup();
});
</script>

<title>Dojo Data</title>
</head>
<body>
<div id="gridDiv" dojoType="dojox.grid.DataGrid" title="Simple Grid" style="width:1000px; height:500px;">
</div>


</body>
</html>

解决方案

在onready函数中,在grid.startup之后,请执行以下操作:

dojo.connect(grid, "onRowClick", grid, function(evt){
    var idx = evt.rowIndex,
        item = this.getItem(idx);

    //  get the ID attr of the selected row
    var value = this.store.getValue(item, "ID");

    //open a dialog or new window or redirect to new JSP

    //to redirect to new jsp, you can set window.location.href to the new url

    //to open a new dialog, i suggest using dijit.dialog 
    //see: http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/test_Dialog.html

    //to open a new window, use window.open
    //http://www.pageresource.com/jscript/jwinopen.htm
});

更多网格示例,位于: http://dojotoolkit.org/documentation/tutorials/1.6/working_grid/

API文档列出了所有可能的事件: http://dojotoolkit.org/api/1.6/dojox/grid/DataGrid#onApplyCellEdit

I have a code which is working fine and displaying some set of values to me in a grid which is dojox.grid.DataGrid. Now i want to perform some event like when i click on a particular row it will redirect me to a new JSP page. Or will open a window where i can do something. How to do that ? Please help me out. thanks.

The code is ::

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="MyPackage.PopulateTextbox" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojo/resources/dojo.css";
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dijit/themes/nihilo/nihilo.css";
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojox/grid/resources/Grid.css";
   @import "http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojox/grid/resources/nihiloGrid.css";

</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojo/dojo.js" djConfig="isDebug: false, parseOnLoad: true"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">

dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.data.ItemFileWriteStore");
</script>
<%
String temp1;
PopulateTextbox obj = new PopulateTextbox();
temp1 = obj.method();
request.setAttribute("variable", temp1); 
%>

<script type="text/javascript">
dojo.ready(function(){
var myVar = <%= request.getAttribute("variable") %>
var storedata={
            identifier:"ID",
            label:"name",
            items: myVar
    };

var store = new dojo.data.ItemFileWriteStore({data: storedata});

    var gridStructure =[[

                      { field: "ID",
                            name: "ID_Emp",
                            width: "40%"
                      },
                      {
                          field: "Names",
                          name: "Name",
                          width: "40%"
                      }

                ]
          ];


     var grid = new dojox.grid.DataGrid({
            id: 'grid',
            store: store,
            structure: gridStructure,
            },
          document.createElement('div'));

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

        /*Call startup() to render the grid*/
        grid.startup();
});
</script>

<title>Dojo Data</title>
</head>
<body>
<div id="gridDiv" dojoType="dojox.grid.DataGrid" title="Simple Grid" style="width:1000px; height:500px;">
</div>


</body>
</html>

解决方案

In your onready function, after grid.startup, do the following:

dojo.connect(grid, "onRowClick", grid, function(evt){
    var idx = evt.rowIndex,
        item = this.getItem(idx);

    //  get the ID attr of the selected row
    var value = this.store.getValue(item, "ID");

    //open a dialog or new window or redirect to new JSP

    //to redirect to new jsp, you can set window.location.href to the new url

    //to open a new dialog, i suggest using dijit.dialog 
    //see: http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/test_Dialog.html

    //to open a new window, use window.open
    //http://www.pageresource.com/jscript/jwinopen.htm
});

more grid examples at: http://dojotoolkit.org/documentation/tutorials/1.6/working_grid/

The API doc lists all the possible events: http://dojotoolkit.org/api/1.6/dojox/grid/DataGrid#onApplyCellEdit

这篇关于在dojox.grid.DataGrid中选择特定行时执行事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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