javascript - JQGrid - SetRowData - Returns success but no data updated - Stack Overflow

I am trying to addedit data into my JQGrid.Currently the first column is populated and then the othe

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}        
],

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}        
],
Share Improve this question edited Sep 21, 2012 at 15:43 MTAG11 asked Sep 21, 2012 at 15:33 MTAG11MTAG11 3962 gold badges8 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1
 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745584986a4634479.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信