执行操作按钮单击事件,按钮放在dojox.grid.DataGrid中。

时间:2012-04-21 11:02:18

标签: javascript jsp button dojo dojox.grid.datagrid

我有dojox.grid.DataGrid。在此显示一组值以及填充了buttons的最后2列,这些列是根据使用formatter中的gridStruture属性从数据库检索的数据动态创建的。现在我的网格很好。按钮也很好。我现在需要做的是当我点击该按钮点击事件上的特定按钮时,我将其重定向到具有特定值的新URL(A)作为该URL中的查询字符串参数传递。而且我不希望我的页面被刷新。就像单击按钮时一样,它会在其他JSP页面上执行操作并显示消息alert("Action is being performed")

我的java脚本代码,我为我的数据网格编码::

<script type="text/javascript">
function getInfoFromServer(){
        $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp?random=" + new Date().getTime(), function (result) {
        success:postToPage(result),
        alert('Load was performed.');
            },"json");
    }


    function postToPage(data){
    alert(data);    
    var storedata = {
        identifier:"ActID",
        items: data
        };
    alert(storedata);

    var store1 = new dojo.data.ItemFileWriteStore({data: storedata}) ;
    var gridStructure =[[

                          { field: "ActID",
                                name: "Activity ID",

                                classes:"firstName"
                          },
                          {
                              field: "Assigned To",
                              name: "Assigned To",

                              classes: "firstName"
                          },
                          { field: "Activity Type",
                                name: "Activity Type",

                                classes:"firstName"
                          },
                          {
                              field: "Status",
                              name: "Status",

                              classes: "firstName"
                          },
                          {
                              field: "Assigned Date",
                              name: "Assigned Date",

                              classes: "firstName"
                          },
                          {
                              field: "Assigned Time",
                              name: "Assigned Time",

                              classes: "firstName"
                          },
                          {
                              field: "Email",
                              name: "Send Mail",
                              formatter: sendmail,
                              classes: "firstName"

                          },
                          {
                              field: "ActID",
                              name: "Delete",
                              formatter: deleteact,
                                classes: "firstName"
                          }

                    ]
              ];
    //var grid = dijit.byId("gridDiv");
    //grid.setStore(store1);

    var grid = new dojox.grid.DataGrid({

        store: store1,
        structure: gridStructure,
        rowSelector: '30px',
        selectionMode: "single",
        autoHeight:true,
        columnReordering:true

        },'gridDiv');

    grid.startup();
    dojo.connect(grid, "onRowClick", grid, function(){
                var items = grid.selection.getSelected();
                dojo.forEach(items, function(item){
                    var v = grid.store.getValue(item, "ActID");
                    getdetailsfordialog(v);

                    function showDialog() {
                        dojo.require('dijit.Tooltip');
                        dijit.byId("terms").show();
                    }

                    showDialog();
                    }, grid);

            });
}

function sendmail(item) {
    alert(item);
      return "<button onclick=http://localhost:8080/2_8_2012/jsp/SendMailReminder.jsp?Send Mail="+item+"'\">Send Mail</button>";

    }
function deleteact(item) {
    alert(item);
      return "<button onclick=http://localhost:8080/2_8_2012/jsp/DeleteActivity.jsp?Activity ID="+item+"'\">Delete</button>";
    }
</script>

我使用$.get调用获取网格数据。在上面的代码字段中,EmailActID实际上是在sendmail中调用每个时间函数deleteactformatter时创建的按钮。显示网格。此外,两个函数中alert(item)的值都是正确的,即各自的值。与alert(item) Delete中的ActID一样,我alert(item) sendmail "shan@gmail.com" button click获得Sendmail现在我想要特定的http://localhost:8080/2_8_2012/jsp/SendMailReminder.jsp?Send Mail="+item+"' button click }(Delete列中的按钮)我的页面

http://localhost:8080/2_8_2012/jsp/DeleteActivity.jsp?Activity ID="+item+"'\"
本页<{1}}列中的

rowClick

Rowclick

打开,其中包含从数据库中检索的项目的值。我也应用了一个{{1}}事件,这也导致了问题,因为当我点击按钮时我的{{1}}事件触发而不是按钮点击事件。这该怎么做。我想过将click事件应用到网格上的每个按钮。但有ID我不知道。请帮我解决这个问题。谢谢..

1 个答案:

答案 0 :(得分:1)

我认为,您需要调整服务器端代码以处理发送邮件的ajax发布请求,并在用户单击按钮时使用dojo.xhrPost方法。您的JS代码可能如下所示:

  function sendMailHandler(evt, item) {
    dojo.xhrPost({
      url: "/2_8_2012/jsp/SendMailReminder.jsp",
      content: {
        'SendMail': item
      },
      error: function() {
        alert("Sent failure");
      },
      load: function(result) {
        alert("Email sent with result: " + result);
      }
    });

    dojo.stopEvent(evt);
  }

  function sendmail(item) {
    return "<button onclick='sendMailHandler(arguments[0], \"" + item +  "\")'>Send Mail</button>";
  }

请注意dojo.stopEvent(evt);中的sendMailHandler用于停止事件冒泡并阻止RowClick加注。

还有dojo.xhrGet具有类似语法来执行ajax GET请求,您可以使用它而不是jQuery的$.get。您也可以在我的示例中使用dojo.xhrGet代替dojo.xhrPost,因为它可能会在没有调整的情况下与您的后端一起使用,但POST(或ajax表单提交)将是在语义上更正确。

关于“尝试注册id =”某事“,您应该调整代码以避免ID重复。或者显示您的代码导致错误。

相关问题