JqG​​rid:我可以知道onSelectRow中点击了哪个动作按钮?

时间:2014-04-09 20:55:10

标签: jqgrid

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

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

谢谢和问候!

1 个答案:

答案 0 :(得分: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");
    //}
}