执行动作的按钮点击事件,按钮被放置内dojox.grid.DataGrid。 [英] Performing action a button click event, button being placed inside dojox.grid.DataGrid.

查看:706
本文介绍了执行动作的按钮点击事件,按钮被放置内dojox.grid.DataGrid。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 dojox.grid.DataGrid 。在这个正在显示一组值随着最后两列充满了其中创建动态的根据数据使用从数据库中检索按钮 格式化 gridStruture 属性。现在我得到我的网格罚款。按钮也上来了罚款。当我在该按钮单击事件我把它重定向到一个新的URL与特定值(A)是作为传递该URL查询字符串参数特定的按钮,点击我现在需要做的是。而且我不希望我的网页被刷新。它就像当一个按钮被点击它执行一些其他的JSP页面上的行动,并显示信息警报(行动正在进行)

I have a dojox.grid.DataGrid. In this a set of values are being displayed along with last 2 columns being filled up with buttons which are created dynamically according to data being retrieved from database using formatter property in gridStruture. Now i am getting the my grid fine. Buttons are also coming up fine. What i need to do now is when i click on a particular button on that button click event i redirect it to a new URL with a particular value(A) being passes as a query string parameter in that URL. And i don't want my page to be refreshed. Its like when a button is clicked it performs action on some other JSP page and displays message alert("Action is being performed").

我的Java脚本code,其中我有codeD为我数据网格::

My java script code where i have coded for my data grid ::

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

我正在使用网格数据 $。获得电话。在上面的code字段电子邮件 ACTID 实际上正在创建的按钮时,每次函数的sendmail deleteact 正在调用的格式。显示网格。此外警报(项目)的两个函数值都上来了正确的,是有各自的值。像警报(项目)删除我收到 ACTID 警报(项目)的sendmail >获得shan@gmail.com现在我想,在一个特定的按钮点击(在的Sendmail 列)我页

I am getting grid data using $.get call. In the above code field Email and ActID are actually buttons being created when each time function sendmail and deleteact are being called up in formatter. Grid is displayed. Also the value of alert(item) in both functions are coming up right that is there respective values. Like for alert(item) in Delete i am getting ActID and alert(item) in sendmail getting "shan@gmail.com" Now i want that on a particular button click(button in Sendmail column) my page

http://localhost:8080/2_8_2012/jsp/SendMailReminder.jsp?Send Mail="+item+"'

按钮点击删除列此页

http://localhost:8080/2_8_2012/jsp/DeleteActivity.jsp?Activity ID="+item+"'\"

与项目的价值从数据库中检索打开。我已经应用了 rowClick 事件也这也是造成问题,因为当我点击u键我的 Rowclick 事件触发,而不是按钮点击事件。如何做到这一点。我想对电网将click事件给每个按钮。但也有ID我不知道。请帮我在这一个。谢谢..

opens up with value of items being retrieved from database. I have applied a rowClick event also which is also causing problem as when i click u button my Rowclick event fires instead of button click event. How to do this. I thought of applying click event to each button on grid. But there ID i don't know. Please help me on this one. Thanks..

推荐答案

我想,你需要的是调整你的服务器端code来处理Ajax post请求发送邮件和使用什么道场.xhrPost 当用户点击按钮的方法。您的JS code可能是这样的:

I think, what you need is adjusting your server-side code to handle ajax post requests for sending mail and use dojo.xhrPost method when user clicks button. Your JS code may look like this:

  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 用于停止事件冒泡和prevents RowClick 认识。

Note that dojo.stopEvent(evt); in sendMailHandler is used to stop event bubbling and prevents RowClick raising.

还有 dojo.xhrGet 类似的语法来执行Ajax GET请求,您可以使用,而不是jQuery的 $。获得。您还可以使用 dojo.xhrGet 而不是 dojo.xhrPost 在我的例子,因为有机会,它会工作与没有调整后端,但 POST (或AJAX表单提交)会更语义正确的。

There is also dojo.xhrGet with similar syntax to perform ajax GET requests, which you can use instead of jQuery's $.get. You can also use dojo.xhrGet instead of dojo.xhrPost in my example, because there is chance that it will work with your back-end without tweaking, but POST (or ajax form submission) would be more semantically correct.

和关于试图注册一个id =东西,你应该调整你的code,以避免重复的ID,或者展示你code导致错误。

And about "Tried to register an id="something", you should adjust your code to avoid IDs duplication. Or show your code causing errors.

这篇关于执行动作的按钮点击事件,按钮被放置内dojox.grid.DataGrid。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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