29

I want to change a particular rows's cell value, I have the row Id. and I have tried using the following. But it doesnt work.

$("#my-jqgrid-table").jqGrid('setCell',rowId,'Currency', '12321');

I am using loadonce: true

Please can someone help me with this. Thanks

Yasser Shaikh
  • 44,064
  • 44
  • 190
  • 271
  • You need post more details about the grid which you use. The *full* definition of `'Currency'` column in `colModel` is really required. Moreover it's important to know *when* (in which context) you call `setCell`. Is the sell which you need to modify is in editing mode? – Oleg Oct 01 '12 at 14:52
  • @All - If you don't have the **rowID** and need to know how to get it, [consider this example](https://stackoverflow.com/a/47330980/1016343). – Matt Jan 25 '18 at 12:52

3 Answers3

63

You can use getRowData and setRowData methods to achieve this (they are working directly with data array):

var rowData = $('#my-jqgrid-table').jqGrid('getRowData', rowId);
rowData.Currency = '12321';
$('#my-jqgrid-table').jqGrid('setRowData', rowId, rowData);
tpeczek
  • 22,947
  • 3
  • 69
  • 75
  • Not sure which version this became available (I'm using `jqGrid-4.5.2`) but `$("#...").getRowData(id)` and `$("#...").setRowData(id, rowData)` work as well. – Jay Sullivan Jul 24 '13 at 20:11
  • 3
    @notfed The fact is that the two methods you have mentioned are from the old API. The desine guidelines for any jQuery plugin are to expose just one method and make others available as a string parameter (jQuery UI widget methods work in the same way) – tpeczek Jul 24 '13 at 21:16
  • 2
    I don't know why this user accept another answer....:) because this is standard solution in jqgrid – Chintan Gor Nov 07 '14 at 12:33
  • @tpeczek it is not working for me. I am using free jqgrid 4.14 version – shv22 May 24 '17 at 17:52
  • @shv22 I can't repro any issue, can you share some more details (via email or something) – tpeczek May 26 '17 at 09:16
  • @tpeczek thanks for concern but I posted a question here https://stackoverflow.com/questions/44164231/can-i-update-an-image-in-jqgrid-cell/44177318?noredirect=1#comment75375176_44177318 and Oleg helped to get it. – shv22 May 26 '17 at 11:02
8

Here is the correct way according to the documentation :-

$("#my-jqgrid-table").jqGrid("setCell", rowid, "Currency", "New value");

Check that all variables are correct as what you did seems correct. loadOnce has no impact, you must have a mistake elsewhere.

  • Are you sure the row name is Currency (not the index)
  • Check the variable rowId, should it be rowid or rowID
Justin Levene
  • 1,379
  • 14
  • 14
  • This worked well in my case: I didn't want the change to trigger the format function, as `setRowData` does. Also, check this Oleg's answer if you want to change local data: https://stackoverflow.com/a/9145342/1863970 – DavidC Aug 02 '17 at 22:48
-4

Thanks all for your effort, with help of a friend at work I managed to get this working with some jquery.

Here is what I did...

$("#" + rowId).find('td').eq('3').html('newText')

here 3 is used because I want to change my 3rd column.

Hope this is useful for someone in future :)

Yasser Shaikh
  • 44,064
  • 44
  • 190
  • 271