简体   繁体   English

如何在 jqgrid 中复制/克隆一行?

[英]How do I copy/clone a row in jqgrid?

I am trying to create a custom button in jqgrid that would allow me to clone a selected row/record.我正在尝试在 jqgrid 中创建一个自定义按钮,它允许我克隆选定的行/记录。 I have currently got this alert working correctly and I am able to display the record id of the selected row with the following code:我目前已使此警报正常工作,并且可以使用以下代码显示所选行的记录 ID:

$buttonoptions = array("#pager",
    array("caption"=>"Clone", "title"=>"Clone selected Record", "onClickButton"=>"js: function(){
        var selr = jQuery('#grid').jqGrid('getGridParam','selrow');
        if(selr) alert(selr);
        else alert('Please select the row you want to Clone first!');
        }"
    )
);
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions);

I was thinking of using the 'getRowData' and 'addRowData' to achieve this with the following code:我正在考虑使用“getRowData”和“addRowData”通过以下代码实现这一点:

var rowData = jQuery('#grid').jqGrid('getRowData',selr);
jQuery('#grid').jqGrid('addRowData',0,rowData,'last');

used like this像这样使用

$buttonoptions = array("#pager",
    array("caption"=>"Clone", "title"=>"Clone selected Record", "onClickButton"=>"js: function(){
        var selr = jQuery('#grid').jqGrid('getGridParam','selrow');
        if(selr)
        var rowData = jQuery('#grid').jqGrid('getRowData',selr);
        jQuery('#grid').jqGrid('addRowData',0,rowData,'last');
        else alert('Please select the row you want to Clone first!');
        }"
    )
);
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions);

but this isn't working.但这不起作用。

I would appreciate some help getting this resolved, as I have been trying for a while without any success and I cannot find any code examples on how to achieve this.我希望能得到一些帮助来解决这个问题,因为我已经尝试了一段时间但没有任何成功,而且我找不到任何关于如何实现这一点的代码示例。

Thank you谢谢

You have a error in if else clause - you missed { } the brackets.您在 if else 子句中有错误 - 您错过了 { } 括号。 It should be它应该是

$buttonoptions = array("#pager",
    array("caption"=>"Clone", "title"=>"Clone selected Record", "onClickButton"=>"js: function(){
        var selr = jQuery('#grid').jqGrid('getGridParam','selrow');
        if(selr) { 
            var rowData = jQuery('#grid').jqGrid('getRowData',selr);
            jQuery('#grid').jqGrid('addRowData',0,rowData,'last');
        } else {
            alert('Please select the row you want to Clone first!');
        }
      }"
    )
);
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM