JQGrid - SetRowData - Returns success but no data updated

12,252
 var success = jQuery("#polarizationTable").jqGrid('setRowData',1,dataToAdd[0]);

JQGrid's first row is 1, not 0. Go figure. Works now, just need to figure out the updating while keeping remaining data intact.

Share:
12,252
MTAG11
Author by

MTAG11

Updated on June 04, 2022

Comments

  • MTAG11
    MTAG11 almost 2 years

    I am trying to add/edit data into my JQGrid. Currently the first column is populated and then the other six are blank and are dependent upon the first column. So I need to add or "edit the blank" the data in the other six columns while the first remains the same.

    Right now I am just trying to get access into the JQGrid to edit my current data. The function below is what I have setup so far. It gets passed the time (the first columns data), the number of ohms (data to enter the grid), and the column name. It builds my data set and then tries to add it to rowid 0. This is hardcoded just because I'm trying to get it to work right now. Then I access the JQGrid, add the rowdata and it actually returns a success, but nothing has been added to the JQGrid.

    *note - this is all done within my javascript file

    function AddRow(elapsedTime, numMOhms, mColumn)
    {
        switch(mColumn) 
        {
            case 'a':
            case 'A':
                dataToAdd = [{TestTime:elapsedTime,RdgA:numMOhms,CorrA:"",RdgB:"",CorrB:"",RdgC:"",CorrC:""}];
                break;
            case 'b':
            case 'B':
                dataToAdd = [{TestTime:elapsedTime,RdgA:"",CorrA:"",RdgB:numMOhms,CorrB:"",RdgC:"",CorrC:""}];
                break;
            case 'c':
            case 'C':
                dataToAdd = [{TestTime:elapsedTime,RdgA:"",CorrA:"",RdgB:"",CorrB:"",RdgC:numMOhms,CorrC:""}];
                break;
        }
        alert(JSON.stringify(dataToAdd));
        var success = jQuery("#polarizationTable").jqGrid('setRowData',0,dataToAdd[0]);
        if(success)
        {
            alert("y");
        }
        DrawGraph(true);
    }
    

    if you replace the last bit with this:

    for(var i=0;i<=dataToAdd.length;i++)
      jQuery("#polarizationTable").jqGrid('addRowData',i+1,dataToAdd[i]);
    

    I can get it to add, but it is a dumb add and just appends that data to the end instead of updating data in that row. I tried modifying it with hardcode and removing the for loop, and no luck.

    Here is what my colModel/colNames looks like.

    colNames:['Minutes','Reading A', 'Corr A', 'Reading B','Corr B','Reading C','Corr C'],
    colModel:[
        {name:'TestTime',index:'TestTime', align:"center", sortable:false},
        {name:'RdgA',index:'RdgA', align:"center", sortable:false},
        {name:'CorrA',index:'CorrA', align:"center", sortable:false},
        {name:'RdgB',index:'RdgB', align:"center", sortable:false},
        {name:'CorrB',index:'CorrB', align:"center", sortable:false},       
        {name:'RdgC',index:'RdgC', align:"center", sortable:false},     
        {name:'CorrC',index:'CorrC', align:"center", sortable:false}        
    ],