JqG​​rid:我可以知道在onSelectRow中单击了哪个操作按钮吗? [英] JqGrid: can I know which action button is clicked in onSelectRow?

查看:75
本文介绍了JqG​​rid:我可以知道在onSelectRow中单击了哪个操作按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格.第一列是每一行的复选框.第二列的每一行都有两个操作按钮:编辑和删除.当单击编辑按钮或删除按钮时,我想知道单击了哪个按钮.

I have a grid. The first column is a checkbox for each row. The second column has two action buttons for each row: edit and delete. When a click on the edit button or delete button happens, I want to know which button is clicked.

$(grid_selector).jqGrid({

url:'loaddata.php',
datatype: "json",
refresh: true,
height: 250,
colNames:[' ', 'ID','Last Sales','Name', 'Stock', 'Ship via','Notes'],
colModel:[
    {   
        name:'myac',index:'', width:90, fixed:true, sortable:false, resize:false, 
        formatter:'actions', 
        formatoptions:{ 
            keys:true,

            delOptions: {
                recreateForm: true, 
                beforeShowForm: beforeDeleteCallback, 
                url: "delete.php",
                mtype: 'POST', 
                onclickSubmit: function(options, rowid) {
                var rowData = $(this).jqGrid("getRowData", rowid);
                    options.url += "?" + $.param({
                    id: rowData.id
                });
                },
                editOptions:{
                    recreateForm: true, 
                    beforeShowForm:beforeEditCallback
                }
            }
        },
    },
    {   name:'id',index:'id', width:100, sorttype:"int", editable: false, hidden: false},  
    {   name:'sdate',index:'sdate',width:90, editable:true, sorttype:"date",unformat: pickDate},
    {   name:'name',index:'name', width:150,editable: true,editoptions:{size:"20",maxlength:"30"}},
    {   name:'stock',index:'stock', width:70, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"},unformat: aceSwitch},
    {   name:'ship',index:'ship', width:90, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}},
    {   name:'note',index:'note', width:150, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}} 
], 
....

   onSelectRow: function(id){
    jQuery(grid_selector).restoreRow(id); 
    $('#jSaveButton_' + id).hide();
    $('#jCancelButton_' + id).hide();
    $('#jEditButton_' + id).show();
    $('#jDeleteButton_' + id).show();    

    // the code above is for disabling inline editing for any click on anywhere of a row
    // but I still want to invoke the edit form when the edit button is clicked
    // via $(grid_selector).editGridRow(id, {} );

    ?????? Can I know know which action button is clicked?    

   },

....
});

请注意我当前onSelectRow()中的评论:

Please note the comment in my current onSelectRow():

// the code above is for disabling inline editing for any click on anywhere of a row
// but I still want to invoke the edit form when the edit button is clicked
// via $(grid_selector).editGridRow(id, {} );

感谢和问候!

推荐答案

我不确定我是否了解您要实现的完整方案.因此,我仅尝试回答您的主要问题:如何在onSelectRow回调内部检测到由于单击了Delete按钮而导致该回调被调用的原因.

I don't sure that I understand full scenario which you are implementing. So I try to answer on your main question only: how one can detect inside of onSelectRow callback that the callback called because Delete button was clicked.

您可以使用onSelectRow的3-d参数.相应的代码可能与以下内容有关:

You can use 3-d parameter of the onSelectRow. The corresponding code could be about the following:

onSelectRow: function (rowid, status, e) {
    var $div = $(e.target).closest(".ui-pg-div");
    if ($div.hasClass("ui-inline-del") && $div.attr("id") === "jDeleteButton_" + rowid) {
        alert("Delete button was clicked");
    }// else if ($div.hasClass("ui-inline-edit") && $div.attr("id") === "jEditButton_" + rowid) {
    //    alert("Edit button was clicked");
    //}
}

这篇关于JqG​​rid:我可以知道在onSelectRow中单击了哪个操作按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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