Author Topic: How to delete row with right mouse click  (Read 3891 times)

stoodin

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 85
    • View Profile
How to delete row with right mouse click
« on: May 14, 2014, 07:12:19 pm »
Hi Paramvir,
I just wonder if you have any examples of how to delete a row with right mouse click.
I have a problem to show a "delete row" menu on the right click.
Here is what I do now:
    $grid.on( "pqgridrowrightclick", function( event, ui ) {
        var rowIndx = ui.rowIndx;         
        $grid.pqGrid("addClass", { rowIndx: rowIndx, cls: 'pq-row-delete' });

// Dialog doesn't work well.
//        var ans = window.confirm("Are you sure to delete row No " + (rowIndx+1) + "?");
//        if (ans) {
            $grid.pqGrid("deleteRow", { rowIndx: rowIndx, effect: true, complete: function () {
                    $grid.pqGrid("removeClass", { rowIndx: rowIndx, cls: 'pq-row-delete' });
                }
            });
//        }
//        else {
//            $grid.pqGrid("removeClass", { rowIndx: rowIndx, cls: 'pq-row-delete' });
//        }
    });

Thanks a lot,

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: How to delete row with right mouse click
« Reply #1 on: May 14, 2014, 07:55:22 pm »
I'm afraid to say there is no live example for right click delete row.

What exactly are you trying to do? you mentioned dialog doesn't work well, are you facing any problem with it.

stoodin

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 85
    • View Profile
Re: How to delete row with right mouse click
« Reply #2 on: May 14, 2014, 08:04:09 pm »
Thanks a lot,
I've managed it after adding a contextMenu plugin
    $.contextMenu({
        selector: '.pq-row-delete',
        callback: function(key, options) {
            if (key == "Delete Row") {
                var ans = window.confirm("Are you sure to delete row No " + (g_dltRowIndx+1) + "?");
                if (ans) {
                    $grid.pqGrid("deleteRow", { rowIndx: g_dltRowIndx, effect: true, complete: function () {
                            $grid.pqGrid("removeClass", { rowIndx: g_dltRowIndx, cls: 'pq-row-delete' });
                        }
                    });
                }
                else {
                    $grid.pqGrid("removeClass", { rowIndx: g_dltRowIndx, cls: 'pq-row-delete' });
                }
            }
            else
                $grid.pqGrid("removeClass", { rowIndx: g_dltRowIndx, cls: 'pq-row-delete' });
               
            g_dltRowIndx = -1;
        },
        items: {
            "Delete Row": {name: "Delete", icon: "delete"},
            "Cancel": {name: "Cancel", icon: "quit"}
        }
    });