How to load a subgrid statically?
Asked Answered
S

1

0

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.

Saker answered 6/2, 2012 at 17:55 Comment(2)
please add some details or code...Calypso
Well there are two ways 1) you can pass it as part of the originating request; or 2) generate it on client side (depending on the nature of data). It's a trivial question if you want to avoid ajax just avoid it.Lorgnon
B
2

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],
                ...
            });
    });
Belovo answered 6/2, 2012 at 19:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.