1

I have a table with formatter action to edit and delete row.

In delete action, I want to show a message in the opened dialog with the id of row to delete. So in beforeShowForm event i get the id with:

beforeShowForm: function (form) {

     var rowid= $("#lista_operaciones").jqGrid('getGridParam','selrow');
     $("td.delmsg", form[0]).html(sprintf(mensaje_borrado, rowid));
},

If I click in the delete button of the selected row, I haven´t any problem, but if i click on delete button of other not selected row i get the id of the selected row.

enter image description here

For example, I have the last row selected, If i click in delete button of the second row, I get the id of the last row.

How I can get the correct id?

Hary
  • 5,690
  • 7
  • 42
  • 79
Alejandro Cuervo
  • 535
  • 1
  • 5
  • 16

4 Answers4

1

I suggest you to use hidden field on the Delete dialog which has id="DelData". It's the row (<tr>) with one cell (<td>) having id of the row which will be deleted. The usage of the field is more safe as the usage of selrow option of grid.

See the answer for the code example. In case of usage multiselect: true option the content of the cell will be comma-separated list of ids of rows which will be deleted.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
0

You need to find the id of the row relative to the Delete button that was clicked, and you need to do so earlier than the beforeShowForm: function.

Assuming the value in question to be the id of the <tr> element, the expression would be :

$(tableSelector).on('click', 'deleteButtonSelector', function() {
    var rowid= $(this).closest('tr').attr('id');
    //do something here to make rowid available to the beforeShowForm function
});

If the id is somehow differently stored, then you will have to adapt the expression.

Beetroot-Beetroot
  • 18,022
  • 3
  • 37
  • 44
0

Your code is doing exactly what it should...you are asking for the selected row with

.jqGrid('getGridParam','selrow');

If I read your question correctly you are looking to add data to the existing Delete Confirmation Dialog, in this case the rowid.

What would probably be best, though a bit more work, would be to add in your own custom button, with the same Trash icon, respond to it's onClick event and then have it add the data to the custom delete confirmation form you would build.

If you just want an extra messagebox/alert with the rowid, you can use something like

delOptions: {onclickSubmit: function(rp_ge, rowid) {alert('RowID: ' + rowid)}}
Mark
  • 3,123
  • 4
  • 20
  • 31
0
var sr = jQuery("#list2").getGridParam('selrow');
rowdata = jQuery("#list2").getRowData(sr);
gsamaras
  • 71,951
  • 46
  • 188
  • 305