jqgrid学习笔录

$("#list").trigger("reloadGrid"); //重新载入jqGrid数据

1 Struts2参数冲突,修改jqgrid.js
        searchString改 search_String; 
searchOper;改search_Oper; 
searchField;改search_Field1;

2 Struts2 编码GBK 导致乱码(设置提交为 AJAX,修改Struts2当表单是Ajax编码为UTF-8): $("#gridTable").jqGrid({
url : "jqGrid01.action",
loadBeforeSend: function(xhr) {
        return xhr.setRequestHeader('isAjax', 'true');
    },



修改struts2.3.1.2源码org.apache.struts2.dispatcher.Dispatcher第677行prepare方法
    原来是:
    if (defaultEncoding != null) {
        encoding = defaultEncoding;
    }
    修改为:
    if (request.getHeader("isAjax") != null) {//判断是否是ajax请求,是的话则采用encoding=utf-8编码
    encoding = "UTF-8";
    LOG.debug("ajax request");
} else if (defaultEncoding != null) {
    encoding = defaultEncoding;
}



struts2定义父类属性同时返回json数据
<result type=”json”> 
<param name=”ignoreHierarchy”>false</param> 
</result 


3


$('#MyGrid').jqGrid({
    url: 'Misc/MyjsonService.svc/GetData',
    editurl: 'Misc/MyjsonService.svc/AddEditDeleteGridRow',
    datatype: 'json',
    colNames: ['UserId', 'UserName', 'Email Address', 'Password Last Changed', 'Locked'],
    colModel: [
                { name: 'UserId', index: 'UserId', hidden:true, editable: true, editrules:{edithidden: true}},
                { name: 'UserName', index: 'UserName', editable: true, width: 200, sortable: false, editrules: { required: true} },
                { name: 'Email Address', index: 'Email', editable: true, width: 500, sortable: false, editrules: { email: true, required: true} },
                { name: 'Password Last Changed', index: 'LastPasswordChangedDate', editable: false, width: 200, sortable: false, align: 'center' },
                { name: 'Locked', index: 'IsLockedOut', sortable: false, editable: true, edittype: "checkbox", formatter: 'checkbox', align: 'center' }
            ],
    rowNum: 20,
    hidegrid: false,
    rowList: [20, 40, 60],
    pager: $('#MyGridPager'),
    sortname: 'UserName',
    viewrecords: true,
    multiselect: false,
    sortorder: 'asc',
    height: '400',
    caption: 'Database Users',
    shrinkToFit: false,
    onPaging: function(pgButton) {
        this.DBUserId = null;
    },
    onSelectRow: function(Id) {
        if (Id && Id !== this.DBUserId) {
            this.DBUserSelect(Id);
        }
    },
    loadComplete: function() {
        if (this.DBUserId)
            this.DBUserSelect(this.DBUserId, true);
    },
    gridComplete: function() {
        var grid = $('#MyGrid');
        var body = $('#AvailableDBUsersArea');
        if ((grid) && (body)) {
            grid.setGridWidth(body.width() - 10);

            //keep the grid at 100% width of it's parent container
            body.bind('resize', function() {
                var grid = $('#MyGrid');
                var body = $('#AvailableDBUsersArea');
                if ((grid) && (body)) {
                    grid.setGridWidth(body.width() - 2);
                }
            });
        }
    }
}).navGrid('#MyGridPager',
        { add: true, edit: true, del: true, refresh: false, search: false }, //general options
        {
        //Options for the Edit Dialog
        editCaption: 'Edit User',
        height: 250,
        width: 520,
        modal: true,
        closeAfterEdit: true,
        beforeShowForm: function(frm) { $('#UserName').attr('readonly', 'readonly'); },
        beforeShowForm: function(frm) { $('#UserId').removeAttr('readonly'); },
        beforeShowForm: function(frm) { $('#UserId').attr('readonly', 'readonly'); }
    },
        {
            //Options for the Add Dialog
            addCaption: 'Add User',
            height: 250,
            width: 520,
            modal: true,
            closeAfterAdd: true,
            beforeShowForm: function(frm) { $('#UserName').removeAttr('readonly'); },
            beforeShowForm: function(frm) { $('#UserId').removeAttr('readonly'); },
            beforeShowForm: function(frm) { $('#UserId').attr('readonly', 'readonly'); }
        },
        {
            //Delete options
            width: 350,
            caption: 'Delete User',
            msg: 'Are you sure you want to delete this User?\nThis action is irreversable.'
        },
        {} //Search options
    );

你可能感兴趣的:(jqGrid)