Search code examples
asp.netasp.net-mvcjqgridhierarchical

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


I have jqgrid with 5 level. I want to export all levels of the grid to excel in a button click how can i do that?

I use jqGrid5.3.0, Visual Studio 2017

here is my code(for 2 level):

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";
                });

            }
        });

    }

if I use navButtonAdd for exportToExcel, It only exports current grid to excel not all levels data. (I add this for a grid in the first level)


Solution

  • In the current implementation of Guriddo jqGrid exporting of subgrids is not supported.

    You can create grouping if applicable and do the export. The grouping is supported in export to Excel, Pdf, Csv and Html