Author Topic: How to update a cell by javascript/jquery after the grid is created?  (Read 5066 times)

lsl

  • Pro Deluxe
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
When users click a button, We need to modify the data shown in the grid

e.g. pic1.jpg

in addition, after the Product name is changed, we need to be able to get the changed fields by the following command

is there a function/method and do this?

var changes = $( ".selector" ).pqGrid( "getChanges", {format: 'byVal'} );
//Format of JSON object returned by this method is as below:           
{
    updateList: [row1, row2..]   
    addList: [row1, row2..]   
    deleteList: [row1, row2..]
}

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: How to update a cell by javascript/jquery after the grid is created?
« Reply #1 on: February 06, 2014, 06:49:12 pm »
You can use the below function updateRow (which would be added in the next version) to programmatically update the cells.

Code: [Select]
$grid.pqGrid("updateRow", {rowIndx: 10, rowData: { "productname": "some name"}});

Code: [Select]
    $.paramquery.pqGrid.prototype.updateRow = function (objP) {
        var that = this,
        options = that.options,
        track = options.track,
        track = (objP.track != null) ? objP.track : track,
        rowIndx = objP.rowIndx,
        rowData = objP.rowData, //new row       
        rowData2 = that.getRowData({ rowIndx: rowIndx }); //old row       
        var obj = { rowData: rowData2 };
        for (var dataIndx in rowData) {
            var oldVal = rowData2[dataIndx],
            newVal = rowData[dataIndx];
            if (track) {
                obj.dataIndx = dataIndx;
                obj.oldVal = oldVal;
                obj.newVal = newVal;
                this.iUCData.update(obj);
            }
            rowData2[dataIndx] = newVal;
        }
        that.refreshRow({ rowIndx: rowIndx });
    };

To get cell changes, use format: 'raw' in getChanges method.

http://paramquery.com/pro/api#method-getChanges