Telerik Forums
UI for ASP.NET MVC Forum
0 answers
521 views

I currently have the following setup and it works fine. However, I need to make my controller endpoint POST and be able to pass the data that will be loaded in the PDF from the client. The examples I have found with fromFile point to a GET endpoint that takes simple parameters like Id but I need to be able to pass the actual content to be loaded in the returned PDF. Hoping someone knows a way if that is at all possible.

JavaScript


        function previewPdf(){
            //I need to pass this doc object to the endpoint
            //var doc = {
            //    case: { caseNumber: 'A12345' },
            //    title: 'Test Doc',
            //    body: $('#Content').data("kendoEditor").value() //getting content from a kendo editor the user is filling out
            //};

            // Create a viewer if you do not have one already.
            var pdfViewer = $("#pdf-viewer").data("kendoPDFViewer");
            if(!pdfViewer){
                pdfViewer = $("#pdf-viewer").kendoPDFViewer({
                    pdfjsProcessing: {
                        file: ""
                    },
                    width: 900,
                    height: window.innerHeight - 150
                }).data("kendoPDFViewer");
            }
            var pdfHandlerUrl = '@Url.Action("GetCourtDocumentPdfBytes", "CourtDocuments")';

                 // I was hoping to make an AJAX call like this and then somehow set the file to the PDF viewer but no luck.
                  //$.ajax({
                  //    type: "POST",
                  //    url: pdfHandlerUrl,
                  //    data: JSON.stringify(doc),
                  //    contentType: "application/json",
                  //    success: function(response) {
                  //      // Use the response (which should be a byte array of the PDF) to update the PDF viewer
                  //      pdfViewer.fromFile(response); // this doesn't work so clearly not setting the right type here.
                  //    }
                  //});

            // Build the desired URL to point to your handler that will return the PDF.
                  
            pdfViewer.fromFile(pdfHandlerUrl); //this is working fine just for a GET endpoint

            $("#wndPdfPreview").kendoWindow({
                modal: true,
                width: 1000,
                height: window.innerHeight - 100
            });
            $("#wndPdfPreview").data("kendoWindow").center().open();           
        }

 

My Controller endpoint.


//this approach is working.

public async Task<FileStreamResult> GetCourtDocumentPdfBytes()
        {
            CourtDocument doc = new CourtDocument { Body = "the Body", Title = "the title", Case = new Case { CaseNumber = "2018123CA01" } };
            string html = await this.RenderViewToString("_JudicialOrder", doc, true);
            var bytes = await _pdfService.CreateFromHtml(html, doc.Case.CaseNumber);

            Stream stream = new MemoryStream(bytes);
            return new FileStreamResult(stream, "application/pdf");
            //return File(bytes, "application/pdf", "test.pdf");
        }

//This is more of what I would need.
public async Task<IActionResult> GetCourtDocumentPdfBytes([FromBody] CourtDocument doc)
        {
            string html = await this.RenderViewToString("_JudicialOrder", doc, true);
            var bytes = await _pdfService.CreateFromHtml(html, doc.Case.CaseNumber);

            Stream stream = new MemoryStream(bytes);
            //return new FileStreamResult(stream, "application/pdf");
            return File(bytes, "application/pdf", "test.pdf"); // not sure what to return here to load the pdfViewer from it in the client.
        }

Michel
Top achievements
Rank 1
Iron
 asked on 28 Dec 2022
1 answer
168 views

I have a grid which needs to have some conditional formatting on certain cells.  I have achieved this via the model, and a client template, which does work.

The style is passed as a field to the client template.
actl3.Bound(o => o.QualifiedNight_Actual).Title("Registered Nurse/Nursing Associate").HeaderHtmlAttributes(new { style = "text-align: center; justify-content: center;overflow: visible !important;white-space: normal !important;" }).ClientTemplate("<div class=#=QualifiedNightColour#>#=QualifiedNight_ActualText#</div>");

The style is

.stWarning {
    background-color: red;
    width: 100%;
    
}

However, there is still padding around the div which remains a different colour. How can I make the entire cell have the desired background colour? I did try applying negative margins to the style, but this only seemed to work for the left side of the cell.

As just using the client template works well apart from this, I'm really not keen on having to add more JavaScript code for this (as there are nine fields in the grid that need this applying).

Thanks

Eyup
Telerik team
 answered on 27 Dec 2022
1 answer
139 views

I have an issue with my page where everything works fine except it will not go to pages 3, 5, and 11.  My datasource is a list of an object in my model.  I can add, save, anything except go to those pages.  Below is my code from the page. I am using Kendo 2020.3.1118 (don't have a license for anything newer).  If I click on the 3, nothing happens if I am on page 2 and click the next page arrow, nothing happens. If I am on page 4 and click the next page arrow nothing happens.  But if I am on page 6 and click it, I go to 7, then 8, etc. until I get to 10.  It only refuses those 3 pages out of the 12 that it creates for my data.  The counter on the bottom right works fine.  And if I take out the pageable ability, my dropdown quits working.  I have only been using Kendo for about a week or so.  Once I get this figured out, this project will actually be complete.  It is the last issue I have to solve.  Any help would be greatly appreciated.  

 @(Html.Kendo().Grid(Model).Name("EditableGrid")
                    .Columns(c =>
                    {
                        c.Command(command => command.Custom("Save").SendDataKeys(true).Click("sendLO2")).Width(95);
                        //c.Command(command => { command.Edit(); }).Width(150);
                        c.Bound(f => f.ID).Title("ID").Width(95);
                        c.Bound(f => f.LoanOfficerID).Title("Loan OfficerID").Width(100);
                        c.Bound(f => f.FullName).Title("Full Name").Width(125);
                        c.Bound(f => f.FirstName).Title("First Name").Width(125);
                        c.Bound(f => f.LastName).Title("Last Name").Width(125);
                        c.Bound(f => f.ReceivingLoanOfficerID).Title("Receiving Loan OfficerID").Width(150);
                        c.Bound(f => f.ReceivingFullName)
                            .ClientTemplate("#=ReceivingFullName.rcvFullName#")
                            .Title("Receiving Full Name")
                            .EditorTemplateName("OptionsLOs")
                            .Sortable(false)
                            .Width(180);
                        c.Bound(f => f.ReceivingFirstName).Title("Receiving First Name").Width(125);
                        c.Bound(f => f.ReceivingLastName).Title("Receiving Last Name").Width(125);
                        c.Bound(f => f.Active).Title("Active").Width(95);
                        c.Bound(f => f.CreatedDate).Title("Created Date").Width(125);
                        c.Bound(f => f.ReceivingEmployeeID).Title("Receiving EmployeeID").Width(125);
                        c.Bound(f => f.ReceivingLOID).Title("Receiving LOID").Width(125);
                        c.Bound(f => f.ReceivingTitle).Title("Receiving Title").Width(125);
                        c.Bound(f => f.ReceivingNMLSID).Title("Receiving NMLSID").Width(125);
                        c.Bound(f => f.ReceivingMobileNumber).Title("Receiving Mobile Number").Width(125);
                        c.Bound(f => f.ReceivingOfficeNumber).Title("Receiving Office Number").Width(125);
                        c.Bound(f => f.ReceivingEmailAddress).Title("Receiving Email Address").Width(125);
                        c.Bound(f => f.ReceivingWebsite).Title("Receiving Website").Width(150);
                        c.Bound(f => f.ReceivingBranchID).Title("Receiving BranchID").Width(125);
                        c.Bound(f => f.ReceivingTandemTeamID).Title("Receiving Tandem TeamID").Width(125);
                        c.Bound(f => f.ReceivingOriginationTeamID).Title("Receiving Origination TeamID").Width(125);
                        c.Bound(f => f.ReceivingPictureURL).Title("Receiving Picture URL").Width(150);
                        c.Bound(f => f.ReceivingQRCodeURL).Title("Receiving QRCode URL").Width(150);
                        c.Bound(f => f.ReceivingActive).Title("Receiving Active").Width(95);
                        c.Bound(f => f.ReceivingDateCreated).Title("Receiving Date Created").Width(125);
                        c.Bound(f => f.ReceivingCreatedBy).Title("Receiving Created By").Width(125);
                    })
                    .ToolBar(toolbar => toolbar.Create())
                    .Editable(editable => editable.Mode(GridEditMode.InCell))
                    .Pageable()
                    .Sortable()
                    .Scrollable()
                    .Filterable()
                    .HtmlAttributes(new { style = "height:650px;" })
                    .DataSource(DataSource => DataSource
                            .Ajax()
                            .PageSize(50)
                            .ServerOperation(false)
                            .Update(update => update.Action("SaveLO", "Home"))
                            .Create(update => update.Action("SaveLO", "Home"))
                            .Model(model =>
                            {
                                model.Id(p => p.ID);
                                model.Field(p => p.ReceivingFullName).DefaultValue(ViewData["defaultLO"] as Nova.ReceivingLO_LO.MVC.Models.LOOptions);
                            })

                        )
                    .Resizable(resize => resize.Columns(true))
        )
Daniel
Top achievements
Rank 1
Iron
 answered on 23 Dec 2022
0 answers
251 views

I am trying to use the PDFViewer to display a PDF downloaded from an Azure Blob.

In my view I have:


// Create a viewer if you do not have one already.
        var pdfViewer = $("#pdfViewer").data("kendoPDFViewer");
        if (!pdfViewer) {
            pdfViewer = $("#pdfViewer").kendoPDFViewer({
                pdfjsProcessing: {
                    file: ""
                },
                width: "100%",
                height: 500
            }).data("kendoPDFViewer");
        };

        // Build the desired URL to point to your handler that will return the PDF.
        var pdfHandlerUrl = "/Home/getBlob/" + selectedRows.BlobID;

        // Make the PDFViewer load the designated file.
        pdfViewer.fromFile(pdfHandlerUrl);

An in my controller (getBlob) I have the following:


var stream = new MemoryStream();
await file.DownloadToAsync(stream);
  stream.Position = 0;
                   
 return new FileStreamResult(stream, "application/pdf");

But in the view - I get a pop-up error message that says: PDF file fails to process.

 

Any suggestions?

 

 

 

 

 

Eddie
Top achievements
Rank 1
 asked on 23 Dec 2022
1 answer
454 views

I've just started a new project and used the latest release of the framework (v2022.3.1109). Unfortunately I've encountered some issues which didn't appear using earlier versions of the framework (pre R1 2022 I believe).

The problems are

  • the datepicker control stretches to 100% of the page, if a width is not set in the html attributes (I can't believe this is the default intended behavior)
  • I cannot reduce the font-size of the datepicker control regardless of where I put the style statement (parent container, html attributes etc..)
  • The same is true for the grid, whereas before font size could be adjusted using the style on the parent div, this no longer works

Is there any documentation detailing the changes from R1 2022 and how to achieve these relatively simple appearance changes?

I'm using bootstrap 5 and the kendo.bootstrap-nordic.min.css  css file.

Thanks

Eyup
Telerik team
 answered on 23 Dec 2022
1 answer
294 views

Hello, i came accross this article

https://feedback.telerik.com/document-processing/1356413-support-pdf-a-3?_ga=2.109487747.748254709.1671465274-760371442.1659361380&_gl=1*1e5wooq*_ga*NzYwMzcxNDQyLjE2NTkzNjEzODA.*_ga_9JSNBCSF54*MTY3MTU0ODg5MS44LjEuMTY3MTU0OTM4Mi42LjAuMA..

which says you can create a PDF/A3 format document but not the embedding. When would be feature available?

 

Regadrs,

Geetha

Martin
Telerik team
 answered on 23 Dec 2022
0 answers
118 views

I'm working on a new project using version v2022.3.1109. There seems to have been a change of behavior since the last version I used. When a call to a grids datasource read method fails, the grid isn't cleared of data, as used to be the case.

This can give a user the impression the call has worked. I can trap data source errors, but there doesn't seem to be a method to clear the current data from the grid.

What's the easiest way to clear the datasource if a read call fails?

The read call looks like:


 $("#Grid").data("kendoGrid").dataSource.read();

Thanks

AP
Top achievements
Rank 1
Iron
Iron
Veteran
 asked on 22 Dec 2022
1 answer
168 views

I just performed an upgrade of our Telerik UI for MVC from version 2021.1.119.545 to 2022.3.1109 via the Upgrade Wizard on the VS 2022 Telerik extension.  But now some of the javascript code is not working properly, in particular the tabStrip disable function.   Here is an example of the code that previously worked fine...

var tabStrip = $("#formTabStrip").kendoTabStrip().data("kendoTabStrip");

tabStrip.disable(tabStrip.tabGroup.children().eq(5));  <== no longer works after upgrade

Any idea why this may be happening?  

Thanks!

Ivan Danchev
Telerik team
 answered on 21 Dec 2022
1 answer
175 views

Hello,

I am Kendo Grid in MVC

The grid is set up for in-cell batch editing. One of the fields is a date field. If the date is selected using date picker the value stays in the cell, whereas if the date value is manually entered the value does not hold in the cell. Any suggestions why the value is not holding in the cell when manually entered.

Thank you

 

Eyup
Telerik team
 answered on 21 Dec 2022
3 answers
384 views
we implemented one global filter for other columns (i removed the columns in below code) but we need to do add the filter to the particular column (date)

@(Html.Kendo().Grid<Model>
            ()
            .Name("Activitiesgrid")
            .Columns(columns =>
            {               

                columns.Bound(c => c.ActivityRecordCreateDate).HeaderHtmlAttributes(new { style = "font-weight: bold;font-size: 13px;" }).HtmlAttributes(new { style = "font-size: 12px" }).Width(50);
                
                columns.Bound(c => c.ActivityDate).HeaderHtmlAttributes(new { style = "font-weight: bold;font-size: 13px;" }).HtmlAttributes(new { style = "font-size: 12px" }).Width(100).Format("{0:M/d/yyyy}");
                

            })
            .ToolBar(tools => tools.Excel().Text("Export"))
            .Excel(excel => excel.AllPages(true)
        .Filterable(true)
            
            )
              .Events(events => events.ExcelExport("incompleteCOATestsGridOnExcelExportActivities"))
            .DataSource(dataSource => dataSource
            .Ajax().Model(m =>
            {
                m.Id(p => p.rowIndex);

            })
            .PageSize(0)
            .Read(read => read.Action("GetKendoActivities", "EventsActivities", new { invokedFromMainMenu = true }))
            .ServerOperation(false)            
            .Events(events=>
            {
                events.RequestStart("request_start");
                events.RequestEnd("request_end");

            })
            )
            .NoRecords()
            .Filterable(filterable => filterable
                .Extra(false)
                .Operators(operators => operators
                        .ForDate(date => date.Clear()
                        .IsEqualTo("Is equal to")
                        .IsGreaterThan("Is After")
                        .IsLessThan("Is Before")
                        .IsNull("Is empty")
                        .IsNotNull("Is not empty"))
                        )
                )
            .Sortable()
            .Pageable()
            .Selectable()
            .NoRecords(x => x.Template("<div class='empty-grid' style ='float: top'></div>"))
            .Events(events =>
            {
                //events.FilterMenuInit("CustomFilter");
                events.FilterMenuOpen("CustomFilterOpen");
            })
// .ClientTemplate("#=AssignedDateFormat(data)#")
)
Eyup
Telerik team
 answered on 19 Dec 2022
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?