一尘不染

在dojox.grid.DataGrid中选择特定行时执行事件

jsp

我有一个运行良好的代码,并在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>

阅读 242

收藏
2020-06-10

共1个答案

一尘不染

在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

2020-06-10