ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: lsl on February 06, 2014, 03:12:38 pm

Title: How to update a cell by javascript/jquery after the grid is created?
Post by: lsl on February 06, 2014, 03:12:38 pm
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..]
}
Title: Re: How to update a cell by javascript/jquery after the grid is created?
Post by: paramvir 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