How to change a row's particular cell value in jqgrid
Asked Answered
H

3

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

Howze answered 1/10, 2012 at 13:53 Comment(2)
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?Oulu
@All - If you don't have the rowID and need to know how to get it, consider this example.Amadaamadas
A
64

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);
Aurilia answered 1/10, 2012 at 14:28 Comment(6)
Not sure which version this became available (I'm using jqGrid-4.5.2) but $("#...").getRowData(id) and $("#...").setRowData(id, rowData) work as well.Woodward
@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)Aurilia
I don't know why this user accept another answer....:) because this is standard solution in jqgridKoy
@Aurilia it is not working for me. I am using free jqgrid 4.14 versionMesothorax
@Mesothorax I can't repro any issue, can you share some more details (via email or something)Aurilia
@Aurilia thanks for concern but I posted a question here #44164731 and Oleg helped to get it.Mesothorax
P
10

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
Priddy answered 13/5, 2015 at 20:4 Comment(1)
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://mcmap.net/q/430485/-how-to-update-value-of-data-in-jqgridBittner
H
-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 :)

Howze answered 2/10, 2012 at 5:2 Comment(6)
It is working, Only when one grid available on page scope. when page will have multiple grids then this will fail.Coleridge
For multiple grids just change to: $("#my-jqgrid-table #" + rowId).find('td').eq('3').html('newText')Priddy
This is really not a safe solution.Kamat
This is not correct answer.. Answer given by tpeczek should be marked as correct answereTarpley
Yeah, this is bad also because you modify the DOM but you do not modify the data behind the grid (i.e. the grid[0].p.data) therefore, if you call 'reloadGrid' it will clobber the change.Polytechnic
Done @MarkCarpenterJr. Wow, my answer was scary.Howze

© 2022 - 2024 — McMap. All rights reserved.