Perform an event on selecting a prticular row in dojox.grid.DataGrid

走远了吗. 提交于 2019-12-25 08:20:41

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/9579428/perform-an-event-on-selecting-a-prticular-row-in-dojox-grid-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!