1

I have a in-line delete button, I want to append more data to the delete message pop-up like this: "Delete selected row with code = 7 ?"

I'm using the following in the delOptions:

beforeShowForm: function ($form) {
var sel_id = $("#list").jqGrid('getGridParam', 'selrow');
$("td.delmsg", $form[0]).html("Delete record with <b>code=" + $("#list").jqGrid('getCell', sel_id, 'cd') + "</b>?");}

The problem is If I click on the delete button without first clicking on any part of the row, the selrow is either null or it gets the previously selected row not the currently selected!

How do I make the row selected when clicking on the trash bin icon?

Any help is appreciated

A E
  • 73
  • 1
  • 3
  • 7

1 Answers1

3

I suppose that you use the example which I posted in the old answer. It was written in case of usage of the Delete button (the part of form editing) from navigator bar.

There are one hidden row in the Delete dialog which could help you. Try this one

beforeShowForm: function ($form) {
    // get comma separated list of ids of rows which will be delete
    // in case of multiselect:true grid or just id of the row.
    // In the code below we suppose that single row selection are used
    var idOfDeletedRow = $("#DelData>td:nth-child(1)").text();
    $form.find("td.delmsg").eq(0)
        .html("Delete record with <b>code=" +
            $(this).jqGrid('getCell', idOfDeletedRow, 'cd') + "</b>?");
    // REMARK: in old versions of jqGrid you can't use $(this) and
    //         will have to use something like $("#list")
}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg, that took care of it. – A E Apr 09 '12 at 17:40
  • While we're at it, is there a way to center the delete dialog in the window? I was able to center it using http://stackoverflow.com/questions/210717/using-jquery-to-center-a-div-on-the-screen but for long grids it always snaps to the top of the window – A E Apr 09 '12 at 18:11
  • @AE: There are many ways how you can implement this. Look at [the demo](http://www.ok-soft-gmbh.com/jqGrid/ChangeDelDialogPosition.htm) from [the answer](http://stackoverflow.com/a/5720456/315935) for example. Another possibility to center the dialog you can see on [another demo](http://www.ok-soft-gmbh.com/jqGrid/CenterEditForm.htm) from [the answer](http://stackoverflow.com/a/3968981/315935). One more way how to place the div (dialog) in the center of the *visible* part of the grid you will find [here](http://stackoverflow.com/a/8778241/315935). You can use the same idea for any dialog. – Oleg Apr 09 '12 at 19:37
  • I tried those solutions, it's centered already but it shows the dialog then the viewport snaps to the top of the window !! – A E Apr 09 '12 at 20:13
  • @AE: Is it not what you need? You want that if the grid is long (have many rows or many columns) the dialog will appears so that the user see it. Is it not so? – Oleg Apr 09 '12 at 20:33
  • the dialog shows then the page is scrolled to the top right away, so the dialog disappears from the viewport, the user has to scroll down to see it – A E Apr 09 '12 at 20:54
  • @AE: I posted you *many* different examples. Everyone has some advantages and disadvantages. The first one which I posted you was [the demo](http://www.ok-soft-gmbh.com/jqGrid/ChangeDelDialogPosition.htm) from [the answer](http://stackoverflow.com/a/5720456/315935). Try "Delete" button on the demo. The demo shows the dialog close to the selected row which need be deleted. Other demos which another source as the position of the dialog. So you should just decide what you want and either choose one from the suggested ways or make simple modification of one from the demos. – Oleg Apr 09 '12 at 21:11
  • @AE: If you would use contextMenu : see [the demo](http://www.ok-soft-gmbh.com/jqGrid/CreateContextmenuFromNavigatorButtons3.htm) from [the answer](http://stackoverflow.com/a/8460480/315935) then the user will don't need to scroll to the navigator bar to click "Delete" button. In the case displaying of the "Delete" dialog close to selected row would be the best way. – Oleg Apr 09 '12 at 21:16
  • really appreciate your patience, here's a screenshot of what is happening: http://www.screenr.com/16d8 – A E Apr 09 '12 at 21:59
  • @AE: From the screen I see that you use [formatter: 'actions'](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter#predefined_format_types) probably. In the case you should use `formatoptions: {delOptions: {afterShowForm: function($form) {...}}}` – Oleg Apr 09 '12 at 22:29
  • @AE: If you will have implementation problems with position of Delete form in formatter: 'actions' you should post new question and I will answer it (I will create a demo for you too). – Oleg Apr 09 '12 at 22:49
  • I think there may be a bug in the actions formatter, if I click on any actions cell (outside the icons), it scrolls to the top of the grid – A E Apr 11 '12 at 22:04
  • @AE: I think that you use it in a wrong way. Look at [the demo](http://www.ok-soft-gmbh.com/jqGrid/ChangeDelDialogPosition1.htm). It works. I think the main problem is that you don't post more full code which you use. Moreover you should ask separate questions to separate problems. – Oleg Apr 11 '12 at 22:12
  • here's the new questions with the code used:
    http://stackoverflow.com/questions/10081713/jqgrid-how-to-center-the-delete-dialog-when-using-formatter-actions
    – A E Apr 11 '12 at 23:05