Thanks, partially what I have been looking for.
Currently I am trying to setup a web-service with a Connector to be able to grab rows from the database to export them to excel, due to the fact that the browser view is paged, only a few are exported.
The code runs until myGrid.toExcel(sURL), where it fails since the header row is empty, not sure any rows are pulled from the webservice at all. I put a break point there but it is never invoked. I can call the webservice from the browser manually, and it breaks into the code alright, returning xml for the entire database as expected, so that part works.
Are there any steps missing for index.cshtml to actusally call the webservice? Not sure if the dataprocessor is needed since I am only Getting not Posting. Shouldn’t
myGrid.load("~/Handlers/ExportConnector.ashx?DatabaseID=1&Table=Table1");
be enough to call the webservice from index.cshtml and actually pull data into the grid? I don’t want the grid to be actually displayed, it’s just a temporary container send data to the Excel Service.
index.cshtml:
@using SquishIt.Mvc
@{
Layout = null;
}
Grid Export Request
@(Html.BundleCss()
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxlayout.css")
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/skins/dhtmlxlayout_dhx_skyblue.css")
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/status_toolbar_layout.css")
.Add("~/Scripts/dhtmlx/dhtmlxWindows/codebase/dhtmlxwindows.css")
.Add("~/Scripts/dhtmlx/dhtmlxWindows/codebase/skins/dhtmlxwindows_dhx_skyblue.css")
.Add("~/Scripts/dhtmlx/dhtmlxForm/codebase/skins/dhtmlxform_dhx_skyblue.css")
.Add("~/Scripts/dhtmlx/dhtmlxToolbar/codebase/skins/dhtmlxtoolbar_dhx_skyblue.css")
.Add("~/Content/Site.css")
.MvcRender("~/Content/SquishIt/UtilityGridExport_#.css"))
<body oncontextmenu="return false;">
<div id='Container' style='position:absolute; top:24px; left:4px; width: 519px; height: 246px;'>
</div>
</body>
<script language="javascript" type="text/javascript">
myGrid = new dhtmlXGridObject('Container'); // initializes grid
myGrid.init();
sURL = "http://dhtmlxgrid.appspot.com/export/excel";
sURL = AddURLParameter(sURL, "FileName", sFileName);
myDataProcessor = new dataProcessor("~/Areas/Utility/Handlers/ExportConnector.ashx"); //lock feed url
myDataProcessor.setTransactionMode("GET", true); //set mode as send-all-by-post
myDataProcessor.setUpdateMode("off"); //disable auto-update
myDataProcessor.init(myGrid); //link dataprocessor to the grid
myGrid.load("~/Handlers/ExportConnector.ashx?DatabaseID=1&Table=Table1");
myGrid.toExcel(sURL);
</script>
@(Html.BundleJavaScript()
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxcommon.js")
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxlayout.js")
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxcontainer.js")
.Add("~/Scripts/dhtmlx/dhtmlxWindows/codebase/dhtmlxwindows.js")
.Add("~/Scripts/dhtmlx/dhtmlxForm/codebase/dhtmlxform.js")
.Add("~/Scripts/dhtmlx/dhtmlxToolbar/codebase/dhtmlxtoolbar.js")
.Add("~/Scripts/dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid.js")
.Add("~/Scripts/dhtmlx/dhtmlxGrid/codebase/dhtmlxgridcell.js")
.Add("~/Scripts/dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_export.js")
.Add("~/Scripts/dhtmlx/dhtmlxDataProcessor/codebase/dhtmlxdataprocessor.js")
.Add("~/Scripts/dhtmlx/dhtmlxConnector/codebase/connector.js")
.MvcRender("~/Content/SquishIt/UtilityGridExport_#.js"))
Handlers/ExportConnector.ashx:
<%@ WebHandler Language=“C#” CodeBehind=“ExportConnector.ashx.cs” Class=“Handlers.ExportConnector” %>
Handlers/ExportConnector.ashx.cs:
using System;
using System.Web;
using System.Web.Services;
using dhtmlxConnectors;
using System.Data.SqlClient;
namespace Handlers
{
///
/// Connector body
///
[WebService(Namespace = “http://tempuri.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ExportConnector : dhtmlxRequestHandler
{
private string _msConnStr; // Connection string to database
public override IdhtmlxConnector CreateConnector(HttpContext context)
{
_msConnStr = ConnectionString.GetTVConnectionString();
var sDatabaseID = Convert.ToInt64(context.Request.QueryString["PSIMDatabaseID"]);
var sTable = context.Request.QueryString["Table"];
SqlConnectionStringBuilder cs = new SqlConnectionStringBuilder(_msConnStr);
cs.InitialCatalog= sDatabaseID ;
var connector = new dhtmlxGridConnector(
sTable,
"*",
"ID",
dhtmlxDatabaseAdapterType.SqlServer2005,
cs.ConnectionString
);
return connector;
}
}
}