This example shows how to add custom function to the designer.
First, you need to add the
StiMvcDesigner
component to the view page. Also, you need to pass the
StiMvcDesignerOptions
object to the constructor. The minimum required options are two actions -
GetReport
and
DesignerEvent
:
@using Stimulsoft.Report.Mvc;
...
@Html.Stimulsoft().StiMvcDesigner(new StiMvcDesignerOptions()
{
Actions =
{
GetReport = "GetReport",
DesignerEvent = "DesignerEvent"
}
})
In the options above we define several actions, and we need to add it in the controller.
The
GetReport()
action loads the report template and returns answer to the client part of the designer using the
GetReportResult()
static method. In the parameters of this method, the report object should be passed:
public ActionResult GetReport()
{
var report = new StiReport();
report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"));
// Add System.Web.Mvc.dll library to the report references
var assemblies = new string[report.ReferencedAssemblies.Length + 1];
Array.Copy(report.ReferencedAssemblies, assemblies, report.ReferencedAssemblies.Length);
assemblies[assemblies.Length - 1] = "System.Web.Mvc.dll";
report.ReferencedAssemblies = assemblies;
return StiMvcDesigner.GetReportResult(report);
}
Finally, we need to add custom function using
AddFunction()
method:
public static string MyFunc(string value)
{
return value.ToUpper();
}
static DesignerController()
{
var ParamNames = new string[1];
var ParamTypes = new Type[1];
var ParamDescriptions = new string[1];
ParamNames[0] = "value";
ParamDescriptions[0] = "Descriptions";
ParamTypes[0] = typeof(string);
// How to add my function
StiFunctions.AddFunction(
"MyCategory",
"MyFunc",
"MyFunc",
"Description",
typeof(DesignerController),
typeof(string),
"Return Description",
ParamTypes,
ParamNames,
ParamDescriptions);
}
...
На скриншоте ниже Вы можете увидеть результат выполнения данного кода: