I have MvcReportViewer component, which I use for reports.
In new version of MvcReportViewer js printReport is like this:
function printReport() {
$find('ReportViewer').exportReport('PDF');
}
Is there a possibility to export PDF only first page ?
I created seperate report (which has subreport of the first page) made changes in MvcReportViewer.js:
function printReport() {
if ($('.printOtherUrl').length > 0) {
window.open($('.printOtherUrl').val(), '_blank');
} else {
$find('ReportViewer').exportReport('PDF');
}
}
In a View that i show my #Html.MvcReportViewer:
When iframe is loaded (i have 500ms setTimeout for height and width too, then i add this input):
$("<input type='hidden' class='printOtherUrl'>").val('#Url.Action(Mvc.Reports.GetDailyReportFirstPage())').appendTo($this.contents().find('body'));
And made ie print button hidden per ShowPrintButton = false of ControlSettings
And my controller action is :
public virtual ActionResult GetDailyReportFirstPage()
{
return this.Report(
ReportFormat.Excel,
SiteReports.DailySummaryMainReport,
new { genDate = Clock.Now() });
}
Related
In my old MVC application, I have a login button once the application main page got loaded I have to explicitly click on login to get into the application. Now I would like to trigger the login_btn click event after my view got loaded via code.
In Jquery called the login_btn trigger event in document.ready function, and in controller I used viewBag option. Which is the best way to achieve
In jquery,
$(document).ready(function () {
$('#login_btn').trigger('click');
});
Its getting called when the page get refreshed.
In controller viewBag
public IActionResult Index(string info)
{
loginModel myModel = new loginModel();
test(); //tried
return View(myModel);
}
public void test()
{
ViewBag.JavaScriptFunction = "login()";
}
gives error login not defined, because before loading the model I am calling the test()
Provide me some info on how to trigger the login automatically after the view page got loaded.
Modifying my original answer, the solution using a flag to control the auto-login would be:
if( alreadyLoggedFlag === false ) {
alreadyLoggedFlag = true;
$('#login_btn').trigger('click');
}
I started down the path of adding an UpdatePanel to my Sharepoint page so that I can respond to events that take place (such as the checking of checkboxes and mashing of radio buttons, etc.). That so far has, however, been wrought with frustration and all that rot, as can be deduced from this question.
So I'm now probably going to traverse (no pun intended) the jQuery route and am trying to figure out/find out how to add jQuery to a WebPart.
Currenlty, I am dynamically creating controls in C# based on what a user selects in the WebPart's Editor (if they elect to show Section 1, I create all the controls for Section 1, etc.).
As an example, I'm currently conditionally creating a RadioButton in C# like so:
var radbtnEmployeeQ = new RadioButton
{
CssClass = "dplatypus-webform-field-input"
};
Now if I want to add jQuery to it, I can add an ID to it like so:
var radbtnEmployeeQ = new RadioButton
{
CssClass = "dplatypus-webform-field-input",
ID = "radbtnEmp"
};
...and then add jQuery of this nature (pseudocode):
$('radbtnEmp').click {
// visiblize/invisiblize other controls, assign certain vals to their properties
}
This seems feasible to me, but how do I go about adding jQuery to a WebPart? Is it a matter of adding a .js file at the same directory level as the *.ascx.cs file, and then referencing it from the *.ascx.cs file, or...???
UPDATE
For POC testing, I added a file to my project named "directpaydynamic.js" with this content:
<script>
$(document).ready(function () {
$('input:radio[name=radbtnEmp]:checked').change(function () {
if ($("input[name='radbtnEmp']:checked").val() == 'Employee?') {
alert("radbtnEmp checked");
}
else {
alert("radbtnEmp not checked");
}
});
});
</script>
(derived from an example here)
...and reference the .js file in my *.ascx.cs file like so:
SPWeb site = SPContext.Current.Web;
site.CustomJavaScriptFileUrl = #"C:\Projects\DirectPaymentWebForm\DirectPaymentSectionsWebPart\DPSVisualWebPart\directpaydynamic.js";
(I dragged the .js file onto the code to get the path)
However, running the solution and mashing the radiobutton causes neither alert() to display, so I reckon I've taken the road that was for a good reason less traveled.
UPDATE 2
Realizing I didn't need the script business (as this is a .js file, not an html file), I removed those, and also put an "at any rate" alert() in the jQuery:
$(document).ready(function () {
alert("What's new, pussycat, whoa-oh-oh-oh-OH-oh?");
$('input:radio[name=radbtnEmp]:checked').change(function () {
if ($("input[name='radbtnEmp']:checked").val() == 'Employee?') {
alert("radbtnEmp checked");
}
else {
alert("radbtnEmp not checked");
}
});
});
...but I still endure an alarming dearth of alerts...
Use below code on Page load method
string url = SPContext.Current.Site.ServerRelativeUrl;
if (!url.EndsWith("/"))
{
url += "/";
}
HtmlGenericControl styleCss = new HtmlGenericControl("link");
styleCss.Attributes.Add("rel", "stylesheet");
styleCss.Attributes.Add("type", "text/css");
styleCss.Attributes.Add("href", url + "Style Library/css/style.css");
HtmlGenericControl JsLink = new HtmlGenericControl("script");
JsLink.Attributes.Add("src", url + "Style Library/js/jquery.min.js");`enter code here`
this.Controls.Add(styleCss);
this.Controls.Add(JsLink);
The thing to do (or perhaps I should write, "a" thing to do) to get this to work is to add code like the following to the end of the WebPart's *.ascx file:
<script>
$(document).ready(function () {
alert("The ready function has been reached");
});
$(document).on("change", '[id$=ckbxEmp]', function () {
alert('Function has been reached');
if ($(this).is(":checked")) {
alert("Checked");
} else {
alert("Not checked");
}
});
</script>
The above works like a champ.
I am creating a report with DevExpress in VS2013 and I need to create it according to a template. The report consists of 2 pages which need to display an image of a page from a PDF en then display data accordingly.
In my first attempt I created 2 report with their according watermark images and then added the second report to the first programmatically.
if (reportModel.Report is RequestBonusPage1)
{
var tweedePagina = new RequestBonusPage2();
secondPage.CreateDocument();
reportModel.Report.Pages.AddRange(secondPage.Pages);
}
If I create the report this way the data needed to display on the second page doesn't get passed, hard coded labels are. Also the watermark image itself is not displayed even though I have the DrawWatermark property set to true.
With my second attempt I removed the watermark image from the second page and added the image with a Picturebox but the labels with the data are then displayed next to the picturebox. I used this link (https://www.devexpress.com/Support/Center/Question/Details/Q323059) as an example for doing this.
Does anyone how I can make these examples work or know any alternatives as of how to achieve this?
If anything is unclear about my explanation don't be afraid to ask.
Kind regards
EDIT:
public ActionResult ExportDocumentViewer()
{
var reportModel = BuildReportModel(ModelSessionHelper.CurrentReportData);
ProcessSpecificReport(reportModel);
return DevExpress.Web.Mvc.DocumentViewerExtension.ExportTo(reportModel.Report);
}
private static void ProcessSpecificReport(ReportModel reportModel)
{
reportModel.Report.CreateDocument();
if (reportModel.Report is SalesReport)
{
var secondPage = new SalesReportPage2();
secondPage.CreateDocument();
reportModel.Report.Pages.AddRange(secondPage.Pages);
}
if (reportModel.Report is RequestBonusPage1)
{
var secondPage = new RequestBonusPage2();
secondPage.SetReportData(reportModel.ReportData);
secondPage.DrawWatermark = true;
secondPage.CreateDocument();
reportModel.Report.Pages.AddRange(secondPage.Pages);
CreateWatermarkRequestBonus(reportModel);
}
}
private static void CreateWatermarkRequestBonus(ReportModel model)
{
model.Report.Pages[0].AssignWatermark(new Watermark
{
Image = Properties.Resources.bonus_request_page_001,
ImageViewMode = ImageViewMode.Zoom,
PageRange = "1",
});
model.Report.Pages[1].AssignWatermark(new Watermark
{
Image = Properties.Resources.bonus_request_page_002,
ImageViewMode = ImageViewMode.Zoom,
PageRange = "2",
});
}
You can use Page.AssignWatermark method to set the watermark for particular page.
Here is example:
var report = new YourReportClass();
//...
report.CreateDocument();
var page = report.Pages[0];
var watermark = new Watermark();
watermark.Text = "Watermark text";
watermark.TextDirection = DirectionMode.ForwardDiagonal;
page.AssignWatermark(watermark);
report.ShowRibbonPreview();
I have a view that I pass to Rotativa (wkhtmltopdf) to get a PDF version of the view for users to print, once they click the "print button":
Here is the rendered view that will be converted to PDF if the user clicks the "print" button
Here is the button code from the view
<div id="print-pdf" align="center">
<a id="print-me" class = "print-btn"
href='#Url.Action("PrintMyView", "Report",
new { id = Model.MonthlyReportID,
clubKeyNo = Model.ClubKeyNumber,
month = Model.ReportMonth,
year = Model.ReportYear }, null)'>Print Report</a>
</div>
Common sense tells me that I need to remove the button before the PDF is generated from the view, so users don't get a PDF with a button on it:
I tried hiding the button (.hide()) and also removing it (.remove())
but the PDF is still rendering with the button:
<script type="text/javascript">
$(document).ready(function () {
$('#print-me').show();
$('#print-pdf').click(function () {
$('#print-me').hide();
});
});
</script>
Anything else that I could try here?
Thanks!
You can do a version for PDF so you can handled what and what no should be printed
what are running in javascript does not work because then executed when the doom is ready, but the Rotativa will not execute any javascript
so, you render just what you need
#if (Model.mustPrint){
<div id="print-pdf" align="center">
<a id="print-me" class = "print-btn" href='#Url.Action("PrintMyView", "Report",
new
{
id = Model.MonthlyReportID,
clubKeyNo = Model.ClubKeyNumber,
month = Model.ReportMonth,
year = Model.ReportYear
}, null)'>Print Report</a>
</div>
}
Try this css:
#media print
{
#print-me
{
display:none;
}
}
ref
Rotativa does not render as print media, but as a browser, you must force rendering as print.
Send the "--print-media-type" argument
Doing this you can use css to hide if the media for print
#media print {
.noprint {
display: none! important
}}
Ex:
return new ViewAsPdf("Details", obj)
{
CustomSwitches = "--print-media-type"
}
Complete example:
return new ViewAsPdf("Details", obj)
{
CustomSwitches = "--print-media-type",
FileName = your_name_report.pdf",
PageOrientation = Orientation.Portrait,
PageSize = Size.A4,
PageMargins = new Margins(0, 0, 0, 0),
PageWidth = 210,
PageHeight = 297
};
I'm trying to prevent the scrolling to the top when using jQuery's .load function. I've read at SO that you can use event.preventDefault(); event.stopPropagation();. Here is the link to this question. But when using beginform, you don't have an event here.
I also tried to put a click event on the submit button, but this also didn't work.
Thanks in advance!
This is the code of the view. When success the function closeFancyReservationCancel is called.
#using (
Ajax.BeginForm("Cancel",
"Reservation",
new AjaxOptions { HttpMethod = "POST",
OnSuccess = "closeFancyReservationCancel"},
new { id = "cancelForm" }))
{
...
}
)
And this is the jQuery function
function closeFancyReservationCancel() {
$.fancybox.close();
$('#reservationList').load(ResolveUrl('~/Reservation/reservationList'));
}
function ResolveUrl(url) {
if (url.indexOf("~/") == 0) {
url = baseUrl + url.substring(2);
}
return url;
}
Here a part of my HTML:
<div id="reservationList" class="tblContainer">
#Html.Action("reservationList", "Reservation")
</div>
The action reservationList returns a view with the table. Only the body of the table has an overflow: auto;.
EDIT: added more information
I have a div with a list of my reservations table. I am using MVC3 to show that list. When press the cancel button, the div will reload by the .load function.
EDIT
Here my HTML view with the table:
Pastebin
You can simply get the Scroll amount before loading. And apply the same scroll amount after load is finished
function closeFancyReservationCancel() {
$.fancybox.close();
var scroll_amount= $('#reservationList').scrollTop();
$('#reservationList').load(ResolveUrl('~/Reservation/reservationList'),
function() {
$('#reservationList').scrollTop(scroll_amount);
});
}
If you want you can also use .scrollLeft() amount.