【问题标题】:JqGrid: can I know which action button is clicked in onSelectRow?JqG​​rid:我可以知道在 onSelectRow 中单击了哪个操作按钮吗?
【发布时间】:2014-04-10 05:50:43
【问题描述】:

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

$(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() 中的注释:

// 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, {} );

感谢和问候!

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    我不确定我是否了解您正在实施的完整方案。所以我试着只回答你的主要问题:如何在onSelectRow 回调中检测到回调调用是因为单击了删除按钮。

    您可以使用onSelectRow 的3-d 参数。对应的代码大概如下:

    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");
        //}
    }
    

    【讨论】:

    • 感谢您的帮助。这满足了我的需要。我希望我上面完全禁用内联编辑但在单击编辑按钮时仍然允许表单编辑的方法并不愚蠢。谢谢!
    猜你喜欢
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    相关资源
    最近更新 更多