Telerik Forums
UI for ASP.NET MVC Forum
1 answer
184 views

Hello,

I am trying to understand the best way to update a submodel that is part of the composition of a grid's row model.

I tried to outline an example below. If I have a PersonViewModel that is part of a CompanyViewModel.

I want to be able to update the PersonViewModel's Name, Id and Email by querying using their email.


public class PersonViewModel
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
}

public class CompanyViewModel { public string CompanyId { get; set; } public string CompanyName { get; set; } public PersonViewModel Owner { get; set; } }

public IActionResult GetPersonByEmail([DataSourceRequest] DataSourceRequest request, string email)
{
	PersonViewModel person = _userService.GetUserInfoByEmail(email);
	return Json(person.ToDataSourceResult(request));
}

@(Html.Kendo().Grid<CompanyViewModel>()
	.Name("companyGrid")
	.Columns(columns =>
	{
		columns.Command(command => { command.Edit();}).Locked(true);
		columns.Bound(c => c.CompanyId );
		columns.Bound(p => p.CompanyName );
		columns.Bound(c => c.Owner.Name);
		columns.Bound(c => c.Owner.Email).EditorTemplateName("PersonEditor");
	})
	.Scrollable(s => s.Height("auto"))
	.DataSource(dataSource => dataSource
		.Ajax()
		.Read(read => read.Action("CompanyRead", "Company"))
		.Model(model =>
		{
			model.Id(p => p.CompanyId);
			model.Field(p => p.Owner).DefaultValue(new PersonViewModel() { Name = "", UserId = "", Id = "" });
		})
	)
)

PersonEditor Template would look something like this?

@model PersonViewModel
@(Html.TextBoxFor(model => model))
@(Html.Kendo().Button()
    .Name("PersonLookupButton")
    .Content("Search")
    .Events(ev => ev.Click("personLookupOnClick"))
)


I could get the dataItem from the grid and set the Id, Name, and Email values via jQuery, but that feels like it is working against the point of using composition in my viewmodel. Is there a way to get the PersonViewModel that is returned by GetPersonByEmail() and bind that directly to the row instead?

 

Thank you!

Eyup
Telerik team
 answered on 07 Mar 2023
1 answer
224 views

Hello

I currently have an kendo grid with PDF export functionality, I am trying to add in the facilities to add a line header text to the exported PDF and have tried using both a grid header text box and a javascript alert on button click, however when I try to do this either the application tries to export indefinitely, or the header text is not included. Can anyone suggest where I may be going wrong with this?


View code:

@(Html.Kendo().Grid<Planner.Models.GetTaskList_Result1>()
                                                                                .Name("grid")
                                                                                .Columns(columns =>
                                                                                {
                                                                                    columns.Bound(p => p.DateCreated).Title("Date Created").Format("{0:dd/MM/yy}").Width(120);
                                                                                    columns.Bound(p => p.TaskNo).Title("TaskNo").Width(90);
                                                                                    columns.Bound(p => p.TaskDescription).Title("Task").Width(200);
                                                                                    columns.Bound(p => p.PriorityText).Title("Priority").Width(90);
                                                                                    columns.Bound(p => p.AreaText).Title("Area").Width(140);
                                                                                    columns.Bound(p => p.QS1).Title("Quality Statement").Width(150);
                                                                                    columns.Bound(p => p.KA1).Title("KLOE Area 1").Width(150);
                                                                                    columns.Bound(p => p.KC1).Title("KLOE Characteristic 1").Width(200);
                                                                                    columns.Bound(p => p.KA2).Title("KLOE Area 2").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.KC2).Title("KLOE Characteristic 2").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.KA3).Title("KLOE Area 3").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.KC3).Title("KLOE Characteristic 3").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.KA4).Title("KLOE Area 4").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.KC4).Title("KLOE Characteristic 4").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.KA5).Title("KLOE Area 5").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.KC5).Title("KLOE Characteristic 5").Width(150).Hidden(true);
                                                                                    columns.Bound(p => p.LeadAssigned).Title("Lead Assigned").Width(120);
                                                                                    columns.Bound(p => p.SupportAssigned).Title("Support Assigned").Width(150);
                                                                                    columns.Bound(p => p.DateDue).Title("Date Due").Format("{0:dd/MM/yyyy}").Width(120);
                                                                                    columns.Bound(p => p.StatusText).Title("Status").Width(120);
                                                                                })
                                                                                .Resizable(resize => resize.Columns(true))
                                                                                .Selectable(selectable => selectable.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
                                                                                .Events(events =>
                                                                                {
                                                                                    events.Change("onChange");
                                                                                    events.PdfExport("GetHeaderText");
                                                                                })
                                                                                .Sortable()
                                                                                .ToolBar(toolBar =>
                                                                                {

                                                                                toolBar.Template(
                                                                                        @<Text>
                                                                                        <b class="FloatRight SearchTopMarginExtra">Search by Task Description/Staff: </b>
                                                                                        <input type="search" id="searchbox" class="SearchRight SearchTopMargin" />
                                                                                        <b class="FloatRight">Date From:</b>
                                                                                        <input type="date" id="DateFrom" />
                                                                                        <b class="FloatRight">Date To:</b>
                                                                                        <input type="date" id="DateTo" />
                                                                                        <button id="clearFiltersButton" class="k-button">Clear Filters</button>
                                                                                         ||
                                                                                        <a class="k-button k-button-icontext k-grid-pdf" href="\#"><span class="k-icon k-i-pdf"></span>Export to PDF</a>
                                                                                        <b class="float-right">Title on PDF:</b>
                                                                                        <input type="text" id="PDFTitle" />
                                                                                        </Text>);
                                                                                })
                                                                                .Pdf(pdf => pdf
                                                                                        .AllPages()
                                                                                        .AvoidLinks()
                                                                                        .PaperSize("A4")
                                                                                        .Scale(0.45)
                                                                                        .Landscape()
                                                                                        .Margin("2cm", "1cm", "1cm", "1cm")
                                                                                        .TemplateId("page-template")
                                                                                        .FileName("Active tasks " + DateTime.Today.ToString("d") + ".pdf")
                                                                                        .ProxyURL(Url.Action("Pdf_Export_Save", "Grid"))
                                                                                    )
                                                                                                .Scrollable(scrollable => scrollable.Enabled(true).Height("600px"))
                                                                                                .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
                                                                                                .DataSource(datasource => datasource
                                                                                                .Ajax()
                                                                                                .Filter(filters =>
                                                                                                {
                                                                                                    filters.Add(f => f.Completed).IsEqualTo(false);
                                                                                                })
                                                                                                .Sort(sort => sort.Add("DateDue").Ascending())
                                                                                                .Model(model => model.Id(p => p.TaskNo))
                                                                                                .Read(read => read.Action("Tasks_Read", "TaskList"))
                                                                                                )

                                                                                                .Pageable(pageable => pageable
                                                                                                .Enabled(false))
                                                                                                .Events(e => e.DataBound("onDataBound"))



    )

Relevant javascript and template:

    
<script type="text/javascript">    

    $(document).ready(function () {
        $("#PDFTitle").keyup(function SetViewData() {
            var val = $("#PDFTitle").val();
           
            var text = document.getElementById('customHeaderText');
            text.val() = val.val();
        })
    });
</script>



<script type="x/kendo-template" id="page-template">
    <div class="page-template">
        <div class="header">
            #: customHeader #

            @Html.Label("", new { id = "customHeaderText" })
        </div>
        <div class="footer">
            <div style="float: right">Page #: pageNum # of #: totalPages #</div>
        </div>
    </div>
</script>

<script type="text/javascript">
    function GetHeaderText(e) {
        var customHeader = prompt('Please enter a title for the PDF');
    }

</script>

 

                                                                                                
Eyup
Telerik team
 answered on 07 Mar 2023
1 answer
477 views

Greetings,

 

Im having trouble getting my grid to order the way i want.  I thought that you could use .DataSource to setup sorting but nothing im seeing come up fits my situation.  I want to sort my "haslinked" individuals to the bottom of the grid.  Thanks!

 

Edit:  i just realized my kendo grid is model vs server side.  Thats what i dont get a .sort after datasource.  Any idea how to sort a grid with this new finding?  I believe it essentially means im trying to organize a grid with dynamic content.

 


@(Html.Kendo().Grid(Model)
      .Name("grid")
      .Columns(columns =>
      {
          columns.Bound(model => model.UserName).Title("UserName");
          columns.Bound(model => model.RoleList).Title("Role(s)");
          columns.Bound(model => model.HasLinkedDistilleries).Title("HasLink");
          columns.Bound(b => b.Id).Template(@<text>@Html.ActionLink("Delete", "Delete", "Account", new { id = item.Id }, null)</text>).Title("");
          columns.Bound(b => b.Id).Template(@<text>@Html.ActionLink("Edit", "Edit", "Account", new { id = item.Id }, null)</text>).Title("");
          columns.Bound(b => b.Id).Template(@<text>@Html.ActionLink("Permissions", "Index", "UserPermissions", new { id = item.Id }, null)</text>).Title("").HtmlAttributes(new {@class="" });
      })
       .ToolBar(tools =>
            {
            tools.Template(@<text>@ToolbarTemplate()</text>);
       })
      .Sortable() // Enable sorting
      .DataSource()d => d......Heres where im having trouble.)
      .Filterable()
      .Scrollable()

Ivan Danchev
Telerik team
 answered on 07 Mar 2023
1 answer
320 views

Hi there,

I recently updated our Kendo files inside our MVC application to version 2023.1.117. And I found an issue on Kendo Tabstrip: that when we setup the default index using .SelectedIndex(0), the tabstrip would setup k-state-active class into the targeted tab instead of the newer k-active class. The same thing happen if we set the .selected(True) at the tabitems.

This is causing problem with the styling and tab content display because of when we start navigating to another tab via clicking, the code won't clear up the k-state-active class. Thus there'll be always 2 active state. Is this a bug from the latest version or is there something that I missed?

Strangely enough, when I checked the MVC demo page of tabstrip, the code won't produce k-state-active class at all. I assume your demo is using the latest version of your code. Why the difference? Cheers.

Aaron
Top achievements
Rank 1
Iron
Iron
 answered on 06 Mar 2023
1 answer
327 views

I have a Grid with the 'Add New Record' functionality implemented with the basic `.Toolbar(t => t.Create())`.

I have my grid set to be `.Editable(e => e.Mode(GridEditMode.Inline))`, along with this: `.Columns(c  => { c => c.Command(x => x.Edit().Visible("editVisible"); })`

Whether I click the Toolbar 'Create' button or I click the 'Edit' button on an already existing record, the inline buttons say 'Update' and 'Cancel' , but I'd like the 'Update' button to say 'Create' when it is a new record.

I'm wondering what might be the best way to accomplish the above?

Ivan Danchev
Telerik team
 answered on 06 Mar 2023
0 answers
75 views

We are currently trying to upgrade from 2019.3.917 to 2023.1.117

Some code that worked fine in the old version is failing in the new with error in kendo.combobox.js line 1221

Error message
Uncaught TypeError: Cannot read properties of undefined (reading 'renderButton')

Line 1221

values: kendo.cssProperties.roundedValues.concat([['full', 'full']])

the debugger is highlighting the second 'full'.

Our code is quite complex but commenting most of it out I get the same thing so a simplified version:

Our html page has this input

<input id="departments" style="width: 500px;" />

Then our javascript to create the combobox is

var $combo = $("#departments);

objKendoCB = $combo.kendoComboBox();

The second line results in the error. (the actual code sets lots of properties but I removed them one by one to end up with an empty method call).

Any ideas welcome!

 

Simon
Top achievements
Rank 1
 asked on 06 Mar 2023
1 answer
137 views

I am upgrading a .NET application from .NET 4.5 to .NET 6.0. As part of the upgrade have upgraded the Kendo.MVC dll as well from Version 2018.3.911.545 to 2022.1.119.0

 

In existing application we use Telerik grid and we use their template methods to define custom templates for Grid, toolbar and footer as shown below

pCol.Template( pT => { } ).Title( "" )
                                                  .Width( "3%" )
                                                  .ClientTemplate(
                                                      " #if (ExcludeFromWorkbook == false && ExcludeBtnExcludeFromWorkbookOnRow == false) {#" +
                                                      "<a class='btn btn-success btn-xs' id='btnIncludeExcludeInd_\"#=Id#\"' title='Row Included in Workbook, Click to Exclude from Workbook' onclick='onIncludeExcludeClick(this)'> <i class='fa fa-plus-square'></i> </a> #}"
                                                      + "if (ExcludeFromWorkbook == true && ExcludeBtnExcludeFromWorkbookOnRow == false) {# " +
                                                      "<a class='btn btn-danger btn-xs' id='btnIncludeExcludeInd_\"#=Id#\"' title='Row Excluded from Workbook, Click to Include in Workbook' onclick='onIncludeExcludeClick(this)'> <i class='fa fa-minus-square'></i> </a> #}"
                                                      + "else{# #}#"
                                                  )
                                                  .HtmlAttributes( new {style = "text-align: center;"} )
                                                  .ClientFooterTemplate( "#=conditionalSum('ExcludeFromWbBtn')#" );

 

  .ToolBar(toolbar =>
                            {
                                if (userCanEdit) //if user has edit rights show save and rest of toolbar template
                                {
                                    toolbar.Template(@<text>
                                                <div class="toolbar" id="toobarid1">
                                                    <input type="type" onblur="checkCommentField(this);" onkeypress="checkCommentField(this);" name="name" value="" class="k-textbox" id="componentComment" maxlength="500" placeholder="Edit values and add comment to enable Save..." style="width: 480px" />
                                                    @item.SaveButton()
                                                </div>
                                    </text>);
                                }
                            }) //e

 

But in the upgraded dll am unable to find the below method definitions

  • public virtual GridTemplateColumnBuilder<TModel> Template(Action<TModel> templateAction) in GridColumnFactory
  • public void Template(Func<Grid<T>, object> template); in GridToolBarCommandFactory
  • public GridBuilder<T> TableHtmlAttributes(object attributes); in GridBuilder  

Kindly let me know whats the equivalent methods available in the new dll to substitute the old ones and the new way of implementing our existing logic.

 

Eyup
Telerik team
 answered on 03 Mar 2023
0 answers
148 views
0

I use Kendo Spreadsheet widget with local data binding in MVC. How can I set the datasource to the spreadsheet to do create, update and delete operation?

I know this example,

https://demos.telerik.com/aspnet-mvc/spreadsheet/datasource

but ajax remote binding is not fine for me, because the excel file has a realy complex header with many merged cells. And remote data fills the first row which overwrite header files. So I use this example:

https://www.telerik.com/forums/loading-data-into-a-specific-row-in-kendo-spreadsheet

After using it data liested in the proper rows, but it's very slow.

So please give me some information to resolve this issue. A have to save modifications of the spreadsheet.

Here I list a simple example of how I bind the data:

ViewModel:

public int ID { get; set; }
    public int Name { get; set; }
    public string Status { get; set; }
}

Action in controller:

public ActionResult Index()
{
    List<ViewModel> model = service.GetData();
    return View(model);
}

View cshtml:

@model List<Namespace.Model.ViewModel>

@section body {

    @(Html.Kendo().Spreadsheet()
        .Columns(3)
        .Name("DataExcel")
        .HtmlAttributes(new { style = "width:auto; height: 770px;" })
        .Toolbar(false)
        .Sheetsbar(false)
        .Events(e => e
            .Select("Scripts.onSelect"))
        .Sheets(sheets =>
        {
            sheets.Add()
            .Name("DataSheet")
            .Columns(columns =>
            {
                // Megbízott neve és státusza + Tantárgy neve
                columns.Add().Width(50);
                columns.Add().Width(100);
                columns.Add().Width(100);
            }).Rows(rows =>
            {
                foreach (var dataRow in Model)
                {
                    rows.Add().Height(50).Cells(cells =>
                    {
                        // Megbízott státusza
                        cells.Add()
                            .Value(dataRow.ID)
                            .VerticalAlign(SpreadsheetVerticalAlign.Center)
                            .Color("black");

                        // Tantárgy neve
                        cells.Add()
                            .Value(dataRow.Name)
                            .VerticalAlign(SpreadsheetVerticalAlign.Center)
                            .Color("black");

                        // Órakeret
                        cells.Add()
                            .Value(dataRow.Status)
                            .VerticalAlign(SpreadsheetVerticalAlign.Center)
                            .Color("black")
                            .Bold(true);
                    }
                }
            });
        })
    )
}
Norbert
Top achievements
Rank 1
 asked on 02 Mar 2023
1 answer
123 views

I have a grid with popup editing. The grid is using a custom editor. The grid has the mobile attribute set.

When adding a record on a mobile(ipad) the editor is showing the hidden fields that accompany the kendo components. See Screen prints

 

 

Anton Mironov
Telerik team
 answered on 02 Mar 2023
1 answer
323 views

I need and older version of UI  for ASP.NET MVC, more exactly 2021.3.1207 which does not have so many changes on widgets and is compatible with jQuery 3.6.0.

I need trial version just to see if I can upgrade from 2017 version and jQuery from 1.10.2 without much effort and rewriting code.

Thanks

Eyup
Telerik team
 answered on 28 Feb 2023
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?