如何静态加载子网格? [英] How to load a subgrid statically?

查看:87
本文介绍了如何静态加载子网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想使用ajax在网格中加载数据.有没有办法将所有数据静态加载到主网格和子网格?

I don't want use ajax to load data in my grid. Theres a way to load all data to main grid and subgrids statically?

在jqGrid文档的示例中,需要参数subGridUrl.但我想要类似的东西:

In the samples from jqGrid Documentation, the parameter subGridUrl, is needed. But I want something like:

var mydata = [ {
// ... some static code for data creation here
 } ]

并在参数data中使用mydata,但是subGrid没有此参数或其他内容.

and using mydata in parameter data, but subGrid don't have this parameter or something else.

推荐答案

如果使用

If you use subgrid as grid you have to create new grid inside of subGridRowExpanded callback. The callback get rowid as a parameter. So if you would get the array of data which can be used as data parameter of the subgrid the subgrid can be defined with datatype: 'local'.

代码架构可以与以下内容有关:

The code schema can be about the following:

var mainGridData = [
        {id: 'm1', ...},
        {id: 'm2', ...},
    ],
    subgridData1 = [
        {id: 's11', ...},
        {id: 's12', ...},
    ],
    subgridData2 = [
        {id: 's21', ...},
        {id: 's22', ...},
    ],
    subgridByMainGridId = {
        m1: subgridData1,
        m2: subgridData2
    };

    $('#mainGrid').jqGrid({
        datatype: 'local',
        data: mainGridData,
        ....
        subGrid: true,
        subGridRowExpanded: function(subgridId, rowId) {
            var subgridTableId = subgridId + "_t";

            $("#" + $.jgrid.jqID(subgridId)).html('<table id="' +
                subgridTableId + '"></table>');
            $("#" + $.jgrid.jqID(subgridTableId)).jqGrid({
                datatype: 'local',
                data: subgridByMainGridId[rowId],
                ...
            });
    });

这篇关于如何静态加载子网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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