如何在 asp.net mvc 中导出到 excel 所有级别的分层 jqgrid?

how export to excel all levels of hierarchical jqgrid in asp.net mvc?

我有 5 级的 jqgrid。 我想单击按钮将所有级别的网格导出到 excel 我该怎么做?

我用jqGrid5.3.0, Visual Studio 2017

这是我的代码(2 级):

function FillJQueryGrid(ProjectIdVal) {
    var myColTemplate = { searchoptions: { sopt: ['cn', 'eq', 'bw', 'bn', 'nc', 'ew', 'en'] } };

    $("#jqGrid").jqGrid({
        url: '@Url.Action("GetTransmittalSumLists", "Report")' + '?ProjectId=' + ProjectIdVal,

        jsonReader: {
            repeatitems: false,
            root: function (obj) {
                return obj.records;
            }
        },
        datatype: "json",
        height: 'auto',
        page: 1,
        colModel: [
            { label: 'transmital id', name: 'ArchiveChecklistMainId_fk', template: myColTemplate, key: true, hidden: true},
            { label: 'transmital no', name: 'trans_ref_no', width: 200 },
            { label: 'transmital subject', name: 'ChkMain_Subject', width: 400 },
            { label: 'transmital date', name: 'trans_date', width: 200 },
            { label: 'Delay', name: 'sum_delay_count', width: 200, color: "#ff0000" }

        ],
        width:"100%",
        loadonce: true,
        autowidth: true,
        rowNum: 20,
        subGrid: true,
        subGridRowExpanded: showChildGridCoding,
        toolbarfilter: true,
        pager: "#jqGridPager",
        ignoreCase: true

    });
    $("#jqGrid").jqGrid('filterToolbar', { searchOperators: true, stringResult: true, searchOnEnter: false, defaultSearch: "cn" });

        };

//***********************************fill grid level 2 *******************************************
    function showChildGridCoding(parentRowID, parentRowKey) {
        var childGridID = "GR"+parentRowID + "_table";
        var childGridPagerID = "GR" + parentRowID + "_pager";

        var childGridURL = '@Url.Action("GetCodingSumLists", "Report")' + '?ArchiveChecklistMainId_fk=' + parentRowKey;

        $('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');

        var subgridDivId = childGridID;
        var $subgrid = $("<table id='" + subgridDivId + "_t'></table>"),
    subgridData = $(this).jqGrid("getLocalRow", parentRowID).details,
    $subgridDataDiv = $("#" + subgridDivId),
    $subgridCell = $subgridDataDiv.closest(".subgrid-data").prev(".subgrid-cell");

        $subgridCell.addClass("green"); // set background color on td.subgrid-cell
        $subgridDataDiv.append($subgrid);

        $subgrid.jqGrid({

            url: childGridURL,
            jsonReader: {
                repeatitems: false,
                root: function (obj) {
                    return obj.records;
                }
            },
            datatype: "json",
            height: 'auto',
            width: "100%",

            page: 1,
            colModel: [
                { label: 'Coding_Id', name:'Coding_Id',key:true,hidden:true},
                { label: 'code', name: 'comp_code' },
                { label: 'revision', name: 'revision',width:500 },
                { label: 'Delay', name: 'sum_delay_count',width:500 }
            ],
            loadonce: true,
            subGrid: true,
            subGridRowExpanded: showChildGridReceiver,
            pager: "#" + childGridPagerID,
            rowNum: rowCount,
            loadComplete: function (data) {

                if (data.records.length <= rowCount) {
                    $("#" + childGridPagerID).hide();
                } else {
                    $("#" + childGridPagerID).show();
                }
                $("[id*='" + subgridDivId + "'].ui-jqgrid-sortable").each(function () {
                    this.style.backgroundColor = "#A3E4D7";
                });

            }
        });

    }

如果我为 exportToExcel 使用 navButtonAdd,它只会将当前网格导出到 excel 而不是所有级别的数据。 (我为第一层的网格添加了这个)

在当前的 Guriddo jqGrid 实现中,不支持导出子网格。

如果适用,您可以创建分组并进行导出。支持分组导出到 Excel、Pdf、Csv 和 Html