将网格数据导出为ex​​cel

时间:2014-03-14 11:08:34

标签: .net asp.net-mvc-3 asp.net-mvc-4 jqgrid jqgrid-asp.net

我是jq grid的新手,并获得了一些绑定数据的代码。在互联网的帮助下,我能够绑定数据,但我可以选择将导出按钮添加到网格,可以将网格的当前数据导出到Excel。有许多代码可用,但我没有以正确的方式得到它。请指导我..

 var bindReports = function () {
                $('#list1').jqGrid('GridUnload');
                $("#list1").jqGrid({
                    url: "GetReportDetails",
                    postData: { startDate: $('#startDate').val(), endDate: $('#endDate').val(), ins_Type: $("#InsuranceType").val(), ass_Clincian: $("#ddlAssignedClician").val() },
                    datatype: "json",
                    mtype: "POST",
                    colNames: ["ID", "First Name", "Last Name", "Date Of Birth", "Date of Intake", "Insurance Type", "Insurance company", "Assigned Clinician"],
                    colModel: [
                            { name: "ID", index: "ID", hidden: true, key: true },
                            { name: "FirstName", index: "FirstName", width: 40, align: "left", sortable: true, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Link('", addParam: "');" } },
                            { name: "LastName", index: "LastName", width: 40, align: "left", sortable: true, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Link('", addParam: "');" } },
                            { name: "DOB", index: "DOB", width: 40, align: "left", formatter: 'date', sorttype: "date", sortable: true },
                            { name: "DOI", index: "DOI", width: 40, align: "left", formatter: 'date', sorttype: "date", sortable: true },
                            { name: "IT", index: "IT", width: 40, align: "left", sortable: true },
                            { name: "IC", index: "IC", width: 50, align: "left", sortable: true },
                            { name: "AC", index: "AC", width: 50, align: "left", sortable: true }],
                    // Grid total width and height
                    //multiselect: true, for checkboxes in first column to select 
                    rowNum: 20,
                    rowList: [5, 10, 15, 20],
                    width: 900,
                    height: "100%",
                    // Paging
                    pager: $("#pager1"),
                    viewrecords: true,

                    // Default sorting
                    //sortname: "FirstName",
                    sortorder: "asc",
                    sortable: true,
                    loadonce: true,
                    hidegrid: false,
                    // Grid caption
                    caption: "Reports List"
                }).navGrid("#pager1", { refresh: false, add: false, edit: false, del: false }, {}, // settings for edit
                                                                                              {}, // settings for add
                                                                                              {}, // settings for delete
                                                                                              { sopt: ["cn"] } // Search options. Some options can be set on column level
                    );
            }

1 个答案:

答案 0 :(得分:0)

Excel导入的实现有不同的方法。有人从网格获取数据并将其发送到服务器,然后服务器生成Excel并将其返回。在我看来,最好不要向服务器发送任何额外的数据。而不是服务器应该直接生成基于postData的Excel导入。 The answer演示了如何生成XLSX文件,another answer为演示提供了ASP.NET MVC中导出的实现。