0
votes

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?    

   },

....
});

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

Thanks and regards!

1

1 Answers

1
votes

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.

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