Aug 19, 2014, 1:42 PM
Can't figure out how to get a filter grid panel to excel
Index.cshtml
@using SortDirection = Ext.Net.SortDirection
@model List<object>
@{
var X = Html.X();
ViewBag.Title = "CMM Log Statistics";
Layout = "~/Views/Shared/_BaseLayout.cshtml";
}
@section headtag
{
<script>
var loadFilter = function (plugin) {
plugin.setValue({
jobnumber: "I",
opnumber: ">1",
partnumber: ""
});
};
</script>
<script>
var submitValue = function (grid, hiddenFormat, format) {
//hiddenFormat.setValue(format);
grid.submitData(false, { isUpload: true });
Store1_Submit(gird);
//exportExcel();
};
</script>
<script type="text/javascript">
var exportExcel = function () {
Ext.net.DirectMethod.request({
store: "store1",
cleanRequest: true,
isUpload: true,
params: { data: App.GridPanel1.getRowsValues() }
});
}
</script>
}
@section example {
<h1>CMM Log Data</h1>
<p>CMM Log Filters allows use of the following operators:</p>
<ext:Hidden ID="FormatType" runat="server" Text="xls" />
<ul>
<li>String: =(equals), +(starts with), -(ends with), *(contains), !(doesn't contain)</li>
<li>Date: >, <,>=, <= or date for equals</li>
<li>Number: >, <,>=, <= or date for equals</li>
<li>Boolean: 1, 0, true, false</li>
</ul>
@(X.Window()
.ID("Window1")
.Width(800)
.Height(400)
.Closable(false)
.Title("Example")
.Maximizable(true)
.Layout(LayoutType.Fit)
.Items(
X.GridPanel()
.ID("GridPanel1")
.Store(X.Store()
.ID("Store1")
.DataSource(Model)
.PageSize(10)
.Model(X.Model()
.Fields(
X.ModelField().Name("timein").Type(ModelFieldType.Date),
X.ModelField().Name("jobnumber").Type(ModelFieldType.String),
X.ModelField().Name("partnumber").Type(ModelFieldType.String),
X.ModelField().Name("opnumber").Type(ModelFieldType.Int),
X.ModelField().Name("machnumber").Type(ModelFieldType.Int),
X.ModelField().Name("qtypass").Type(ModelFieldType.Int),
X.ModelField().Name("adjqtypass").Type(ModelFieldType.Int),
X.ModelField().Name("adjqtyfunctional").Type(ModelFieldType.Int),
X.ModelField().Name("adjqtyscrap").Type(ModelFieldType.Int),
X.ModelField().Name("cmmreason").Type(ModelFieldType.String),
X.ModelField().Name("machsuper").Type(ModelFieldType.String),
X.ModelField().Name("cmmoperator").Type(ModelFieldType.String)
//,
//X.ModelField().Name("Date").Type(ModelFieldType.Date),
//X.ModelField().Name("Size").Type(ModelFieldType.String),
//X.ModelField().Name("Visible").Type(ModelFieldType.Boolean)
)
)
.Sorters(X.DataSorter().Property("jobnumber").Direction(SortDirection.ASC))
)
.ColumnModel(
X.DateColumn().Text("Time In").DataIndex("timein").Align(Alignment.Center).Format("yyyy-MM-dd:hh:mm"),
X.Column().Text("Job").DataIndex("jobnumber").Align(Alignment.Center),
X.Column().Text("OpNum").DataIndex("opnumber").Align(Alignment.Center),
X.Column().Text("Machine").DataIndex("machnumber").Align(Alignment.Center),
X.Column().Text("Pass").DataIndex("qtypass").Align(Alignment.Center),
X.Column().Text("Adj").DataIndex("adjqtypass").Align(Alignment.Center),
X.Column().Text("Fun").DataIndex("adjqtyfunctional").Align(Alignment.Center),
X.Column().Text("Scrap").DataIndex("adjqtyscrap").Align(Alignment.Center),
X.Column().Text("Supervisor").DataIndex("machsuper"),
X.Column().Text("Part").DataIndex("partnumber"),
X.Column().Text("Reason").DataIndex("cmmreason"),
X.Column().Text("Operator").DataIndex("cmmoperator")
//.Renderer(RendererFormat.UsMoney)
//,
//X.DateColumn().Text("Date").DataIndex("Date").Align(Alignment.Center).Format("yyyy-MM-dd"),
//X.Column().Text("Size").DataIndex("Size"),
//X.Column().Text("Visible").DataIndex("Visible").Align(Alignment.Center)
// .Renderer("return (value) ? 'Yes':'No';")
)
.Plugins(
X.FilterHeader()
)
.BottomBar(
X.PagingToolbar()
.HideRefresh(true)
)
.DockedItems(
X.Toolbar()
.Dock(Dock.Bottom)
.Items(
X.Button()
.Text("Excel")
.ToolTip("Export To Excel")
.Listeners(ev =>
{
ev.Click.Handler = "submitValue(#{gridpanel1}, #{FormatType}, 'xls')";
}),
X.Button()
.Text("Case Sensitive")
.EnableToggle(true)
.AllowDepress(true)
.ToggleHandler("var plugin = this.up('grid').filterHeader; plugin.caseSensitive = this.pressed; plugin.applyFilter();"),
X.Button()
.Text("Load Filters")
.Handler("loadFilter(this.up('grid').filterHeader);"),
X.Button()
.Text("Get Fields Values")
.ToolTip("Get Values of Fields")
.Handler("var values = Ext.encode(this.up('grid').filterHeader.getValue()); Ext.Msg.alert('Fields Values', values);"),
X.Button()
.Text("Get Filter Values")
.ToolTip("Get Filter Values of Grid")
.Handler("var filters = Ext.encode(this.up('grid').filterHeader.getFilterValues()); Ext.Msg.alert('Filter Values', filters);"),
X.Button()
.Text("Clear Filters")
.Handler("this.up('grid').filterHeader.clearFilter();")
)
)
.Listeners(l =>
{
l.AfterRender.Handler = "this.filterHeader.fields[0].setIconCls('#Magnifier')";
l.AfterRender.Delay = 10;
})
)
)
}
OverviewController.cs:using CMMStats;
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Linq;
using System.Xml;
using System.Text;
using System.Xml.Xsl;
namespace Ext.Net.MVC.Examples.Areas.GridPanel_FilterHeader.Controllers
{
public class OverviewController : Controller
{
public ActionResult Index()
{
//CMMEntities cmm = new CMMEntities();
MechanicalEntities cmm = new MechanicalEntities();
List<object> items = new List<object>(
from i in cmm.LogDates
//where i.timein.Date > DateTime.Today.AddMonths(-12)
select new { i.opnumber,
i.timein,
i.cmmreason,
i.machnumber,
i.partnumber,
i.jobnumber,
i.machsuper,
i.cmmoperator,
i.adjqtyfunctional,
i.adjqtypass,
i.adjqtyscrap,
i.qtypass,
i.timecomplete
});
return View(items);
}
protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
{
XmlNode xml = e.Xml;
this.Response.Clear();
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.AddHeader("Content-Disposition", "attachment; filename=toExcel" + DateTime.Now.ToString() + ".xls");
XslCompiledTransform xtExcel = new XslCompiledTransform();
xtExcel.Load(Server.MapPath("~/Excel.xsl"));
xtExcel.Transform(xml, null, Response.OutputStream);
this.Response.End();
}
public ActionResult ExportToXls(string data)
{
//string format = this.FormatType.Value.ToString();
//XmlNode xml = data.xml;
Ext.Net.SubmitHandler submitData = new Ext.Net.SubmitHandler(data);
XmlNode xml = submitData.Xml;
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.AddHeader("Content-Disposition", "attachment; filename=CMM Stats Reports" + DateTime.Now.ToString() + ".xls");
XslCompiledTransform xtExcel = new XslCompiledTransform();
xtExcel.Load(Server.MapPath("~/Excel.xsl"));
xtExcel.Transform(xml, null, Response.OutputStream);
return View();
}
}
}
it seems to be passing my page markup to the controller.
Last edited by halburchal; Aug 19, 2014 at 2:11 PM.
Reason: copied the wrong controller