9

I want to customize the delete dialog message. Based on a selected row? I want to display a message something like "Delete selected row: $selectedRow.columnValue? " How can i do that?

heisenberg
  • 9,665
  • 1
  • 30
  • 38
user620339
  • 851
  • 3
  • 20
  • 42

2 Answers2

16

You can use beforeShowForm or afterShowForm of the delGridRow to overwrite the text of the conformation dialog.

For example

beforeShowForm: function ($form) {
    $("td.delmsg", $form[0]).html("Do you really want delete the row with <b>id=" +
         $("#list").jqGrid('getGridParam','selrow') + "</b>?");
}

(see the old demo) will display the confirmation dialog like the following:

enter image description here

You can easy modify the example to display any other information about the deleting row. You can use getRowData or getCell to get some information from the deleting row.

UPDATED: See the answer for additional information.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • +1 - yeah, I didn't think when I wrote my answer earlier. Thanks. You're definitely the jqgrid guru! – David Hoerster Aug 02 '11 at 16:01
  • @Oleg: Hei, nice solution. But what if I want to get the message from server side? How do I specify the Url from which the message should be loaded? I am using .Net MVC 3. – Mohayemin Oct 03 '11 at 11:50
  • @Mohaimin: It's full depend on how you use jqGrid in ASP.NET MVC 3. If you has `$("td.delmsg", $form[0]).html(...)` inside of aspx page for example the text `"Do you really want delete the row with id="` can be generated by server code and be not a constant. – Oleg Oct 03 '11 at 12:05
  • If id contains dot `.` or other special characters, hex code appears instead. How to show real id in delete prompt ? – Andrus Mar 11 '15 at 20:30
  • @Oleg If there are multiple selected rows, how to select all row ids in prompt ? How to show id if it contains `.` or other special characters ? Currently hex code appears instead of dot – Andrus Mar 11 '15 at 20:39
  • @Andrus: The current question has no relation to keyboard navigation. I posted you already [the demo](http://www.ok-soft-gmbh.com/jqGrid/OK/SetFocusInDeleteForm1.htm) which shows that if one set attributes `href: "#"`, `role: "button"` and `tabindex` on the buttons of Delete dialog then one can set focus by usage `$("#dData").focus()`. – Oleg Mar 11 '15 at 20:39
  • @Oleg I modified comments and removed keyboard navigation parts. Questions about multiple ids print and id decoding are kept since those are related to this question. – Andrus Mar 11 '15 at 20:41
  • @Andrus: I tried, but I could not reproduce any problem with ids having `.`. See [the demo](http://www.ok-soft-gmbh.com/jqGrid/OK/SetFocusInDeleteForm2.htm). – Oleg Mar 11 '15 at 20:49
2

if you start dialog with $('#dialog_id') then before you open your dialog change his html

$('#dialog_id').html('Delete selected row:' + $selectedRow.columnValue?);
$('#dialog_id').dialog();
Senad Meškin
  • 13,597
  • 4
  • 37
  • 55