How to load a subgrid statically?

早过忘川 提交于 2020-01-11 13:09:20

问题


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?

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
 } ]

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


回答1:


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],
                ...
            });
    });


来源:https://stackoverflow.com/questions/9164764/how-to-load-a-subgrid-statically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!