简体   繁体   English

单击自定义按钮获取行数据

[英]Get row data on custom button click

I am using free jqgrid 4.14 and I need to have a custom image (some kind of mail icon) in my grid and when the image is clicked it should open a modal window having a form and which has the data of clicked row in the message field of form and also has other couple of field like sender mail id, receiver mail id and also a subject. 我正在使用免费的jqgrid 4.14,我需要在网格中有一个自定义图像(某种邮件图标),单击该图像时应打开一个具有形式的模态窗口,该窗口具有消息中单击行的数据表单字段,还有其他几个字段,例如发件人邮件ID,收件人邮件ID以及一个主题。

So, I was able to have a custom image in my grid. 因此,我能够在网格中拥有一个自定义图像。 Now, we have onSelectRow property by which we can get the id of the clicked row and we have getRowData which will give the data of the columns. 现在,我们具有onSelectRow属性,通过该属性我们可以获取单击的行的ID,并具有getRowData将提供列的数据。

So, I made changed onSelectRow a bit like this 因此,我对onSelectRow进行了如下更改

onSelectRow: function(id){ 
            if(id && id!==lastSel){ 
                jQuery(this).restoreRow(lastSel); 
                lastSel=id; 
                var rowId = $(this).getRowData(lastSel);
            } 
            jQuery(this).editRow(id, true); 
        }

Now, this will give the data of each row when it is clicked. 现在,这将在单击时提供每一行的数据。 But how will I get same functionality when my custom image is clicked? 但是,单击自定义图像后如何获得相同的功能?

EDIT: I need something like this- 编辑:我需要这样的东西-

http://www.ok-soft-gmbh.com/jqGrid/Admin3.htm http://www.ok-soft-gmbh.com/jqGrid/Admin3.htm

But here I am not able to find the image like here it finding 但是在这里我找不到像这里找到的图像

There are many ways to implement the requirement. 有很多方法可以实现要求。 One from the easiest one I described in the answer . 我在回答中描述的最简单的一种。 You can add the column with formatter: "actions" 您可以使用formatter: "actions"添加该列formatter: "actions"

{
    name: "act", template: "actions", width: 25,
    formatoptions: { editbutton: false, delbutton: false }
}

and the jqGrid option, which specify additional custom buttons 和jqGrid选项,它们指定其他自定义按钮

actionsNavOptions: {
    mailicon: "fa-envelope-o",
    custom: [
        {
            action: "mail",
            position: "first",
            onClick: function (options) {
                alert("Mail for rowid=" + options.rowid);
            }
        }
    ]
}

See https://jsfiddle.net/OlegKi/3tuxg71z/ 参见https://jsfiddle.net/OlegKi/3tuxg71z/

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

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