0

I am working on an MVC project, which uses JQGrid. In one of my grids, I have a subgrid. Within the subgrid one of the columns is a dropdownlist. I would like to catch the change event of this dropdownlist, so that I can set a default value of the next cell along using the selected item.

I used Firebug to see the Id of the <select> html, and tried the following code, which doesn't fire the alert:

$('#MySelectId').change(function() {
        alert('Test');
    });

This approach worked when using the modal edit form, but I am using inline editing, and would like to catch the event when the user changes the dropdownlist on the grid.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Joe
  • 215
  • 1
  • 6
  • 13

1 Answers1

5

You can define dataEvents property as the part of editoptions. In the dataEvents you defines your custom 'change' event handle and jqGrid will make the binding after the corresponding cell will be initialized in the editing mode. See here or here examples.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks again Oleg, your a star! – Joe Mar 28 '11 at 16:27
  • I am trying to set the value of the textbox next to my dropdown, but I cannot seem to get a handle on it. I have tried using.. – Joe Mar 29 '11 at 09:38
  • var row = $(e.target).closest('tr.jqgrow'); var rowId = row.attr('id'); $("text#" + rowId + "_MyColumnName", row[0]).html(myValue); – Joe Mar 29 '11 at 09:40
  • Sorry, I didn't research this properly, you have already answered this question from another user. I changed my last line to '$("#" + rowId + "_MyColumnName").val(myValue);' – Joe Mar 29 '11 at 09:53
  • @Joe: Sorry I don't understand the context of the code. Do you use form editing and you want to change the textedit field of the form for the column "MyColumnName" based on the value `myValue` from the dropdown box? In the case the ids of the edit forms will have ids with the same names like the column name and you can just do `$("#MyColumnName").val(myValue)`. Because I don't exactly understand your code example (especially the context) I am not sure that is what you need. – Oleg Mar 29 '11 at 09:59
  • @Oleg: I read your answer here[link](http://stackoverflow.com/questions/5247138/jqgrid-change-cell-value-and-stay-in-edit-mode) and solved my problem. During my inline edit, I was trying to allow the user to set a in a textbox within the row, using a dropdownbox from the same row. My problem was accessing the textbox to assign it's new value. But After reading your answer I was able to fix the code as in my last comment. – Joe Mar 29 '11 at 10:14
  • @Joe: You are write, the answer are very close to your problem. I am glad to hear that I could help you. Best wishes! – Oleg Mar 29 '11 at 13:24