从一个jqGrid中删除行并将其添加到另一个jqGrid

时间:2012-08-08 05:01:04

标签: javascript jquery ajax jquery-plugins jqgrid

我有两个jqGrids(“in_table”和“out_table”),它们的数据除外。感谢我在this post上收到的帮助,现在我了解了如何添加可自定义的按钮。按下按钮时,我想删除表中的行并将其添加到另一行。

按下按钮时调用的以下代码是不可预测的 - 它会工作一段时间然后停止工作!
控制台显示错误:

Uncaught TypeError: Cannot read property 'name' of undefined 

代码:

function sign_in_out_action(myself,rowid,icol,cellcontent,e){
    var this_row = myself.getRowData(rowid);
    if( in_out_button_content(cellcontent)== "In"){
    alert('Signing OUT');
    this_row.in_out = "Out";
    $('#out_table').jqGrid('addRowData',1,this_row);
    myself.delRowData(rowid);
    }
    else{
    if( in_out_button_content(cellcontent)== "Out"){
        alert('Signing in');
        this_row.in_out = "In";
        $('#in_table').jqGrid('addRowData',1,this_row);
        myself.delRowData(rowid);
    }
    else{
        alert("what?  "+in_out_button_content(cellcontent));
    }
    }

删除和添加数据似乎非常简单。我很感激任何洞察我做错了什么。

1 个答案:

答案 0 :(得分:0)

我认为你可以定义两个函数,一个是为网格添加一行,另一个是删除一行网格。

然后,您可以为自定义按钮添加点击功能。

// delete row
function deleteRow(tableId, rowId) {
        $('#' + tableId).jqGrid('delRowData', rowId);
        return false;
}


    var index = 999;
// add a row
    function addRow(tableId, c1, c2) {
        var datarow = { Id: c1, Name: c2 };

        var lastsel2 = index;
        index++;
        var su = jQuery('#' + tableId).addRowData(lastsel2, datarow, 'last');
        if (su) {
            jQuery('#' + tableId).jqGrid('editRow', 0, true);
        }
    }

c1,c2是列值。(您可以有五列,因为您可以定义c1,c2,c3,c4,c5)。

以下代码用于获取单元格值:

var c1 = $('#' + tableId).getCell(rowId, 'Id');
var c2 = $('#' + tableId).getCell(rowId, 'Name');