javascript JQGrid - SetRowData - 返回成功但未更新数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12533658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:27:28  来源:igfitidea点击:

JQGrid - SetRowData - Returns success but no data updated

javascriptjqgrid

提问by MTAG11

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.

我正在尝试将数据添加/编辑到我的 JQGrid 中。目前,第一列已填充,然后其他六列是空白的,并且依赖于第一列。所以我需要在其他六列中添加或“编辑空白”数据,而第一列保持不变。

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.

现在我只是想访问 JQGrid 来编辑我当前的数据。下面的功能是我迄今为止设置的功能。它传递了时间(第一列数据)、欧姆数(进入网格的数据)和列名。它构建我的数据集,然后尝试将其添加到 rowid 0。这是硬编码的,因为我现在正试图让它工作。然后我访问 JQGrid,添加行数据,它实际上返回成功,但没有向 JQGrid 添加任何内容。

*note - this is all done within my javascript file

*注意 - 这一切都在我的 javascript 文件中完成

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.

我可以让它添加,但它是一个愚蠢的添加,只是将该数据附加到末尾而不是更新该行中的数据。我尝试用硬编码修改它并删除 for 循环,但没有运气。

Here is what my colModel/colNames looks like.

这是我的 colModel/colNames 的样子。

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

采纳答案by MTAG11

 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.

JQGrid 的第一行是 1,而不是 0。请看图。现在可以工作,只需要在保持剩余数据完整的同时找出更新。