jqGrid常用操作命令

  • 设置default参数
    jQuery.extend(jQuery.jgrid.defaults, {
            datatype: 'json',
            autowidth: true,
            height: 380,
            sortorder: "asc",
            rownumbers: true,
            viewrecords: true,
            //recordpos: 'left',
            multiselect: true,
            pager: '#pager',
            rowNum: 20,
            rowList: [20, 50, 100],
            loadComplete: function (data) {
                if (data.status != "Success")
                    showErrorTip(data.message);        
            },
            loadError: function (xhr, st, err) {
                var template = "服务器端响应出现异常:   类型:{0}, 状态号: {1} {2} ,异常描述:{3}";
                showErrorTip(format(template, st, xhr.status, xhr.statusText, err));
            },
            dataFilter: function (data, type) {
                return data.replace(/"\\\/(Date\([0-9-]+\))\\\/"/gi, 'new $1');
            }
        });
  • 加载数据
    $("#list").jqGrid({
                    url: '/Credential/GridData',
                    colNames: [' ', '证件名称', '持有人', '证件编号', '签发机关', '到期时间', '提醒倒计时', '证件关键字', '专业', '类别', '级别', '继续教育', '描述','是否过期','是否借出', '电子照片'],
                    colModel: [{ name: 'myac', width: 30, align:'center', fixed: true, sortable: false, resize: false, formatter: 'actions', "formatoptions": formatoptions },
                               { name: 'Name', index: 'CredentialName', formatter: viewFmatter},
                               { name: 'OwnerText', index: 'OwnerText', align: 'center' , width: 80 },
                               { name: 'CredentialNo', index: 'CredentialNo' },
                               { name: 'AuthorizeUnit', index: 'AuthorizeUnit' },
                               { name: 'ExpireDate', index: 'ExpireDate', formatter: 'date', formatoptions: dateFormat, width: 105, align: 'center' },
                               { name: 'RemindDays', index: 'RemindDays', width: 80, align: 'center' },
                               { name: 'Keys', index: 'Keys', width: 80 },
                               { name: 'Professional', index: 'Professional', width: 80},
                               { name: 'CredentialType', sortable: false, width: 80},
                               { name: 'Rank', index: 'CredentialRankID', width: 80},
                               { name: 'Education', index: 'EduTotal', width: 100},
                               { name: 'Description', sortable: false},
                               { name: 'isExpired', hidden:true},
                               { name: 'IsBorrowed', hidden:true},
                               { name: 'image', sortable: false, width: 80, align: 'center', formatter: imgFmatter, hidden: !isCanMaintainImage},
                               ],
                    sortname: 'CredentialID',
                    caption: "证件列表",
                    multiselect: isCanDel,
                    editurl:"/Credential/delete",
                    loadComplete: credential_load_complete_handler,
                });   
    function imgFmatter(cellvalue, options, rowObject) {
        var template = "<span class='ui-icon ui-icon-image' style='margin-left:10px;cursor:pointer;' onclick='uploadFile({0})'></span>";
        return format(template, options.rowId);
    }
    var formatoptions = { "editbutton": false, "delbutton": isCanDel,
        delOptions: {
            afterSubmit: function (response, postdata) {
                var delFaiMessage = "删除记录失败,{0}";
                eval("var data = " + response.responseText);
                resetTip();
    
                if (data.status == "Success") {
                    showSuccessTip("删除记录成功");
                }
                else {
                    showErrorTip(format(delFaiMessage, data.message));
                }
    
                return [true, ''];
            }
        }
    };
    

      

  • Reload
    $.fn.reloadGrid = function (filterData) {
        this.jqGrid('setGridParam', { page: 1, postData: filterData }).trigger("reloadGrid");
    }
    

      

  • Multi Select
    jQuery.mis.batchDelete = function () {
        var s = jQuery("#list").jqGrid('getGridParam', 'selarrrow');
    
        if (s == "") {
            alert(format("请选择要删除的{0}", para.CNName));
            return;
        }
        
        $.each(s, function (key, val) {
            var url = format("/{0}/Delete/{1}", moduleName, val);
            var row = $("#list").getRowData(val);  //根据ID拿到一行的数据
    
            $.post(url, function (data) {
                deleteHandler(data, row);
            });
        });
    };
    function deleteHandler(data, row) {
        var delSucMessage = "删除记录 {0} 成功;  ";
        var delFaiMessage = "删除记录 {0} 失败,{1}  "
        var title = $(row.Name).text(); // $(row.Name).text()替代row.Name可以去除链接
    
        if (data.status == "Success") {
            var message = format(delSucMessage, title); 
            showSuccessTip(message);
        }
        else {
            var message = format(delFaiMessage,row.Name, data.message);
            showErrorTip(message);
        }
    }
    

      

  • 双击选中某行
    $("#select").jqGrid({
                    colNames: [' ', '姓名', '性别','职位', '部门', '员工状态', '手机', '电话'],
          ...
                    ondblClickRow: select
                });
            });
     function select() {            
                var myGrid = $('#select');
                var id = myGrid.jqGrid('getGridParam', 'selrow');
                var name = myGrid.jqGrid('getCell', id, 'Name');
                var tel = myGrid.jqGrid('getCell', id, 'Tel');
                var phone = myGrid.jqGrid('getCell', id, 'Phone');
                var callback = eval($("#sDialog").dialog("option", "callbackFunc"));
    
                callback(id, name, tel, phone);
                $("#sDialog").dialog("close");
            }
    

      

  •  设置自定义列
                jQuery("#list").jqGrid('navGrid','#pager',{add:false,edit:false,del:false,search:false,refresh:false});
                jQuery("#list").jqGrid('navButtonAdd','#pager',{
                    caption: "自定义列",
                    title: "自定义要显示的列和顺序",
                    onClickButton : function (){
                        jQuery("#list").jqGrid('columnChooser');
                    }
                });
    

      

posted @ 2012-08-31 10:58  Season2009  阅读(1130)  评论(1编辑  收藏  举报