Search code examples
c#.netasp.net-mvc-2jqgridexport-to-excel

JQGrid export to excel works locally, but never in integration enviroment


<form action="" method="post" id="SaveIndicationsExportForm">
    <table cellspacing="0" cellpadding="0" id="hover" style="float: left;">
        <tbody>
            <tr>
                <td class="hoverButtonLeft off">
                </td>
                <td class="hoverButtonMid off">
                    <div onclick="resultsGridExportToExcel()" buttonize="true" buttonized="true">
                        <img src="/Extranet/img/buttons/excel_icon.gif"> Export To Excel
                    </div>
                </td>
                <td class="hoverButtonRight off">
                </td>
                <td class="hoverButtonSpace off">
                </td>
            </tr>
        </tbody>
    </table>
</form>

So that's the form that I have on my page. Basically, this is just a pseudo form, that I can use to trigger the export action on the page for the JQGrid element. Here is the onClick method that the form is tied to:

function resultsGridExportToExcel()
{
    var exportUrl = '/extranet/mvc/Indications.cfc/SavedIndicationsExportToExcel?id=3'; 
    var postData = jQuery('#resultsGrid').jqGrid('getGridParam', 'postData'); 
    $.each(postData, function(key, value) 
    { 
        exportUrl += '&'+key+'='+encodeURIComponent(value); 
    }); 
    $('#SaveIndicationsExportForm').attr('action', exportUrl).submit(); 
}

And here is the #resultsGrid that the function uses. It's put on the top of the page using embedded c# code on the view:

<%
    var grid = Chatham.Web.Models.Indications.SavedIndication.GetGrid("#resultsGrid", Url.Action("SavedIndications", "Indications"), "columnChooser", 500, 800);
%>

And getGrid looks this like:

public static JqGridDefinition GetGrid(string tableId, string actionUrl, string pageUrl, int height, int width)
{

            var gridDefinition = new JqGrid.JqGridDefinition(
                tableId,
                actionUrl,
                pageUrl);
            gridDefinition.RowList = new List<int>() { 25, 50, 100, 500 };

            gridDefinition.AlwaysShowSortingButtons = true;
            gridDefinition.Grouping = true;
            gridDefinition.GroupingColumn = "CreatedBy";
            gridDefinition.ShowGroupColumn = true;
            gridDefinition.GroupingTitle = string.Format("['<b>{0}0{1}</b>']", "{", "}");
            gridDefinition.SetExportToExcel(
                "SaveIndicationsExportForm",
                System.Web.VirtualPathUtility.ToAbsolute("~/mvc/Indications.cfc/SavedIndicationsExportToExcel?id=3"));
            gridDefinition.ShowAdvancedSearch = true;
            gridDefinition.Height = height;
            gridDefinition.Width = width;
            gridDefinition.Multiselect = false;
            gridDefinition.AlwaysShowSortingButtons = true;
            gridDefinition.SearchToolbar = false;
            gridDefinition.NoResultsMessage = "No Saved Indications Found";

            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Nickname", "NickName", true, true, 80, false));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Created By", "CreatedBy", true, true, 80, false, true));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Notional", "Notional", true, true, 80, false, FilterHelper.DateNumberSearchOptions));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Effective Date", "EffectiveDate", true, true, 95, true, true, FilterHelper.DateNumberSearchOptions));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Maturity Date", "MaturityDate", true, true, 95, true, true, FilterHelper.DateNumberSearchOptions));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Term (YR)", "Term", true, true, 50, false, FilterHelper.DateNumberSearchOptions));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Amort. Term Yr", "AmortTermMonths", true, true, 95, true, FilterHelper.DateNumberSearchOptions));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Product", "Product", true, true, 50, false, true));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Rate/Price", "KeyRate", true, true, 95, true, FilterHelper.DateNumberSearchOptions));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("PV01", "PV01", true, true, 95, true, FilterHelper.DateNumberSearchOptions));

            var calculateDate = new JqGrid.JqGridColumnDefinition("Calculate Date", "RateTimeStamp", true, true, 95, false, FilterHelper.DateNumberSearchOptions);
            calculateDate.CustomFormatterDelegate = new CustomFormatter(DateTimeFormatting);
            gridDefinition.AddColumn(calculateDate);

            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Group", "Project", true, true, 95, true, true));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Option Strike", "CapStike", true, true, 95, true));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Trade Type", "Permission", true, true, 95, true));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Profit", "Profit", true, true, 95, false));
            gridDefinition.AddColumn(new JqGrid.JqGridColumnDefinition("Actions", "actions", true, true, 95, false));


            return gridDefinition;
}

That's really all I got at the moment. If you need to see anything else let me know. But I can export fine in a local environment and then as soon as I try in integration it doesn't work, just brings me to a blank page and IE says like it's having trouble diagnosing an issue and brings me to a generic error page.

Thanks guys.


Solution

  • Try accessing url /extranet/mvc/Indications.cfc/SavedIndicationsExportToExcel?id=3 on local environment on local machine and then see what will happen then access the same url on the integration and see if you have the same result (you might need to ad some parameters to url ) . if this will work in local and won't work in integration it is not a javascript fault. make sure that the integration have the same url pattern it can for example have /extranet/ part missing or it might require some additional paramers like session or your export to excell have some libs missing (this should show an error though at least in logs).

    hope this could help.