JqGrid自定义获取编辑中单元格的值

本文介绍了一种自定义方法,用于从jqGrid中获取正在编辑的单元格的值,包括不同输入类型如select、checkbox、password等的处理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用法:

var grid = $("#jqGrid");
var cellvalue =grid .jqGrid("getEditingCellValue", grid [0], rowId, iRow, iCol);

自定义方法:

$.jgrid.extend({
            getEditingCellValue: function (grid, rowId, iRow, iCol) {
                var $t = grid, fr,
                    errors = $.jgrid.getRegional(grid, 'errors'),
                    edit = $.jgrid.getRegional(grid, 'edit');
                if (fr !== null) {
                    var cc = $("td:eq(" + iCol + ")", $t.rows[iRow]), v, v2,
                        cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm),
                        p = $(cc).offset();
                    switch (cm.edittype) {
                        case "select":
                            if (!cm.editoptions.multiple) {
                                v = $("#" + rowId + "_" + nmjq + " option:selected", $t.rows[iRow]).val();
                                v2 = $("#" + rowId + "_" + nmjq + " option:selected", $t.rows[iRow]).text();
                            } else {
                                var sel = $("#" + rowId + "_" + nmjq, $t.rows[iRow]), selectedText = [];
                                v = $(sel).val();
                                if (v) { v.join(","); } else { v = ""; }
                                $("option:selected", sel).each(
                                    function (i, selected) {
                                        selectedText[i] = $(selected).text();
                                    }
                                );
                                v2 = selectedText.join(",");
                            }
                            if (cm.formatter) { v2 = v; }
                            break;
                        case "checkbox":
                            var cbv = ["Yes", "No"];
                            if (cm.editoptions) {
                                cbv = cm.editoptions.value.split(":");
                            }
                            v = $("#" + rowId + "_" + nmjq, $t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
                            v2 = v;
                            break;
                        case "password":
                        case "text":
                        case "textarea":
                        case "button":
                            v = $("#" + rowId + "_" + nmjq, $t.rows[iRow]).val();
                            v2 = v;
                            break;
                        case 'custom':
                            try {
                                if (cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
                                    v = cm.editoptions.custom_value.call($t, $(".customelement", cc), 'get');
                                    if (v === undefined) { throw "e2"; } else { v2 = v; }
                                } else { throw "e1"; }
                            } catch (e) {
                                if (e === "e1") { $.jgrid.info_dialog(errors.errcap, "function 'custom_value' " + edit.msg.nodefined, edit.bClose, { styleUI: $t.p.styleUI }); }
                                else if (e === "e2") { $.jgrid.info_dialog(errors.errcap, "function 'custom_value' " + edit.msg.novalue, edit.bClose, { styleUI: $t.p.styleUI }); }
                                else { $.jgrid.info_dialog(errors.errcap, e.message, edit.bClose, { styleUI: $t.p.styleUI }); }
                            }
                            break;
                    }
                }
                return v2;
 
            }
        });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值