0

I have jqrid with multiple columns and rows loaded via JSON. Currently on click of a UPDATE button i am sending all the grid data to server as JSON as below.

$("#updateTradeDetail").click(function () {
        var griddata = $("#tradeDetailGrid").jqGrid('getGridParam', 'data');        
        $.ajax({
            url : "${pageContext.request.contextPath}" + "/XXxxxx/tools/updateTrades",          
            type : "POST",          
            data: JSON.stringify(griddata),         
            dataType: 'html',
            contentType: "application/json; charset=utf-8",
            success : function(msg) {
                alert("Response on update " + msg);             
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert("Error" + thrownError);
            }
        });
    });

How to send only the specific column values that has multiple rows to the server?

minil
  • 6,895
  • 16
  • 48
  • 55

1 Answers1

0

If you need to send the data from only one column then getCol would be a good alternative to getGridParam("data"). The second parameter of getCol defines the format of the returned data. One should be careful in usage of getCol because it uses unformatter to get the data from the grid cells (from <td> elements) and so the data returned by getCol and getGridParam("data") can be a little different.

One more remark. The usage of getGridParam("data") get you not all the data if you don't have a column in the grid which contains the rowid (for example the column having key: true property in colModel). So to get full data one need get getGridParam("data") and getGridParam("_index"). See the answer, this one, this one and many other.

Probably the most safe and simple way do do what you need is just making copy of the array returned by getGridParam("data") and modifying it by removing unneeded properties. I want to stress about the importance of making copies because getGridParam("data") returns the reference to array with internal data used by jqGrid. So if you would makes some changes in it then the changes will be applyed on the grid on the next refresh (on sorting, paging and so on).

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