简体   繁体   中英

How to Pass the JQGrid Cell Value to Jquery Function using Link Button

My JQGrid cloumns like,

    colNames: ['Job ID', 'MailId','Save'],
    colModel: [
                { name: 'JobId', index: 'JobId', width: 120, align: 'left', editable: true },
                { name: 'MailId', index: 'MailId', width: 150, align: 'left', editable: true },

                {
                    name: 'Save', index: 'Save', width: 100, sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a href='#' id="saveLinkId">Save</a>";

                    }
                }

I create the Save link button at the end of JQGrid cell.

I need to pass clicked row's JobId and MailID to jquery function when click the link button in a row.How to do this?

In the above example you have given, the rowObject parameter in the formatter function will hold all the values in that row. So can use rowObject.JobId for your JobId and rowObject.MailId for your MailId.

I would recommend you to use beforeSelectRow (or onCellSelect ) to detect click on <a> in the "Save" column. The answer explains what you can do. Another answers: this one and this one could be also interesting for you.

In your case beforeSelectRow could looks like below

beforeSelectRow: function (rowid, e) {
    var $self = $(this),
        iCol = $.jgrid.getCellIndex($(e.target).closest("td")[0]),
        cm = $self.jqGrid("getGridParam", "colModel");
    if (cm[iCol].name !== "Save") {
        return true;
    }

    alert ($self.jqGrid("getCell", rowid, "JobId"));
    return false;
}

Additionally you should consider which value you use as id in the input data. The value build so name rowid - the value of id attributes of <tr> elements (the rows of the grid). If for example either JobId or MailId (one from the two columns) contains unique values for every row then you can use the value from the column as the rowid. To do this you need just add key: true to the corresponding column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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