jqGrid动态列绑定 [英] jqGrid dynamic column binding

查看:93
本文介绍了jqGrid动态列绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何动态绑定jqGrid?这些列在设计时不可用,而仅在运行时可用.

How to bind jqGrid dynamically?. The columns are not available at design time but will only be available only at runtime.

在当前的jqGrid设计中,必须预先填充colmodels和其他属性才能使网格正常工作.

In the current jqGrid design the colmodels and other properties needs to be pre-populated for the grid to work correctly.

非常感谢您对此方向的任何投入.

Any input in this direction is greatly appreciated.

推荐答案

在document.ready中尝试一下:

Try this in document.ready:

$.ajax(
    {
       type: "POST",
       url: "SomeUrl/GetColumnsAndData",
       data: "",
       dataType: "json",
       success: function(result)
       {
            colD = result.colData;
            colN = result.colNames;
            colM = result.colModel;

            jQuery("#list").jqGrid({
                jsonReader : {
                    cell: "",
                    id: "0"
                },
                url: 'SomeUrl/Getdata',
                datatype: 'jsonstring',
                mtype: 'POST',
                datastr : colD,
                colNames:colN,
                colModel :colM,
                pager: jQuery('#pager'),
                rowNum: 5,
                rowList: [5, 10, 20, 50],
                viewrecords: true
            })
       },
       error: function(x, e)
       {
            alert(x.readyState + " "+ x.status +" "+ e.msg);   
       }
    });
setTimeout(function() {$("#list").jqGrid('setGridParam',{datatype:'json'}); },50);

这对我来说很好.

这篇关于jqGrid动态列绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆