zoukankan      html  css  js  c++  java
  • 自定义jqGrid编辑列中的控件

    /*******************************************
    * Description:
    * 自定义jqGrid编辑列中的控件
    *
    * 可格式化的类型:
    * 1)PopupDialog     弹出框.可选择数据并返回值到编辑列
    * 2)DateTime        日历控件
    *
    * DateTime调用方法:
    * 在编辑列中加属性  formatter: JqGridFormatCell.ToDateTime
    
    * PopupDialog调用方法:
    *   1.给编辑列加属性
    *     formatter: JqGridFormatCell.ToPopupDialog ,
    *     formatoptions: { UserControl: "<%=ucAirline.ClientID %>" }
    *
    *   2.页面最下方添加以下代码 (将弹框返回值赋给编辑列)
    $("#<%=ucAirline.ClientID %>_datapicker").DataPicker("option", "callback", function (text, value) {
    JqGridFormatCell.SetValue(text);
    });
    注:弹出框用户控件(UCAirlinePopupDialog.ascx)需自行引用至页面,并将其隐藏.
    *
    * Author:
    *******************************************/
    var JqGridFormatCell = {
        _createdPopupButton: function (rowData, gridID) {
            var row = eval("(" + rowData + ")");
            var btnImgSrc = global_ApplicationPath + "/Styles/images/search.gif";
            var args = "'" + gridID + "'" + ",'" + row.rowKey + "'" + ",'" + row.colName + "'" + ",'" + row.userControlID + "'";
            var strPopupBtn = '&nbsp;&nbsp;<img style="cursor:pointer" src="' + btnImgSrc + '" onclick="JqGridFormatCell.showPicker(' + args + ')" />';
            $("#" + row.rowKey + "_" + row.colName).css("width", "85%").after(strPopupBtn)
        },
    
        showPicker: function (gridID, rowKey, colName, userControlID) {
            $("#" + gridID).setSelection(rowKey, true);
            var $textbox = $("#" + rowKey + "_" + colName);
            userControlID = userControlID + "_datapicker";
    
            $("#" + userControlID).DataPicker("Clear");
            $("#" + userControlID + "txtKeyDP").val($textbox.val());
            $("#" + userControlID + "hlOpenDP").click();
    
            $("body").data("CurrentCellTextbox", $textbox);
        },
    
        SetValue: function (value) {
            $("body").data("CurrentCellTextbox").val(value);
        },
    
        beforEditRow: function (gridID, rowid) {
            //ToPopupDialog
            $("#" + rowid).find(":hidden[name='hiddenPara_ToPopup']").each(function (i) {
                $(this).parent().attr({ name: "hiddenPara_ToPopup", value: this.value });
                $(this).remove();
            });
    
            //ToDateTime
            $("#" + rowid).find(":hidden[name='hiddenPara_ToDate']").each(function (i) {
                $(this).parent().attr({ name: "hiddenPara_ToDate" });
                $(this).remove();
            });
        },
    
        afterEditRow: function (gridID, rowid) {
            //ToPopupDialog
            $("#" + rowid).find("td[name='hiddenPara_ToPopup']").each(function (i) {
                JqGridFormatCell._createdPopupButton($(this).attr("value"), gridID);
            });
    
            //ToDateTime
            $("#" + rowid).find("td[name='hiddenPara_ToDate']").each(function (i) {
                $(this).find(":text").datepicker({ changeMonth: true, changeYear: true, dateFormat: DATE_FORMAT });
            });
        },
    
        ToPopupDialog: function (cellValue, options) {
            if (!options.colModel.formatoptions.UserControl) {
                $.jError("formatoptions.UserControl is not defined");
                throw Error();
            }
            var rowKey = options.rowId;
            var colName = options.colModel["name"];
            var gridID = options.gid;
            var userControlID = options.colModel.formatoptions.UserControl;
    
            var strJson = "{rowKey:'" + rowKey + "',colName:'" + colName + "',userControlID:'" + userControlID + "'}";
            var strHtml = '<input type="hidden" name="hiddenPara_ToPopup" value="' + strJson + '" />';
    
            if (cellValue == undefined) {
                return strHtml;
            }
            return cellValue + strHtml;
        },
    
        ToDateTime: function (cellValue, options) {
            var strHtml = '<input type="hidden" name="hiddenPara_ToDate" />';
    
            if (cellValue == undefined) {
                return strHtml;
            }
            return cellValue + strHtml;
        }
    };
  • 相关阅读:
    N点虚拟主机管理系统(For Windows2003/2008)功能及介绍
    淘宝API开发系列商家的绑定
    在linux上使用ASP
    petshop4.0 详解之五(PetShop之业务逻辑层设计)
    vsFTPd 服务器
    中国联通短信如何 对接
    淘宝API开发系列开篇概述
    “VPS FTP应用”目录存档
    使用c#+(datagrid控件)编辑xml文件
    Centos 5.3 Nginx+php+mysql配置 独立的 Subversion (SVN)服务器
  • 原文地址:https://www.cnblogs.com/captainR/p/3342711.html
Copyright © 2011-2022 走看看