Telerik Forums
UI for ASP.NET Core Forum
1 answer
202 views

Hi

I follow the Kendo Core Grid Demo- Editing Custom Editor here https://demos.telerik.com/aspnet-core/grid/editing-custom

but when I click on the add record button, I got an error "Uncaught TypeError: Cannot read property 'CategoryName' of null"

I suspect is is due client template field name with a dot (.ClientTemplate("#=Category.CategoryName#"))

I even downloaded the demo sample file for both core and MVC to run it locally  and turn out MVC version work but .Net Core version has the same error.

Is this a bug in Core version? can anyone advice? Thank you

 

 

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ProductName);
        columns.Bound(p => p.Category).ClientTemplate("#=Category.CategoryName#").Sortable(false).Width(180);
        columns.Bound(p => p.UnitPrice).Width(130);
        columns.Command(command => command.Destroy()).Width(150);
    })
    .ToolBar(toolBar =>
        {
            toolBar.Create();
            toolBar.Save();
        })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:550px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Events(events => events.Error("error_handler"))
        .Model(model =>
        {
            model.Id(p => p.ProductID);
            model.Field(p => p.ProductID).Editable(false);
            model.Field(p => p.Category).DefaultValue(
                ViewData["defaultCategory"] as Kendo.Mvc.Examples.Models.CategoryViewModel);
        })
        .PageSize(20)
        .Read(read => read.Action("EditingCustom_Read", "Grid"))
        .Create(create => create.Action("EditingCustom_Create", "Grid"))
        .Update(update => update.Action("EditingCustom_Update", "Grid"))        
        .Destroy(destroy => destroy.Action("EditingCustom_Destroy", "Grid"))
    )
)

Nikolay
Telerik team
 answered on 13 Sep 2019
2 answers
472 views

Hi,

I have a Kendo Grid as per the code below

     @(Html.Kendo().Grid<ReportCompetencyViewModel>()
         .Name("listGrid")
         .BindTo(Model.ReportCompetency.OrderBy(x => x.DisplayOrder))
         .Columns(columns =>
         {
             columns.Bound(c => c.Code).ClientHeaderTemplate("Code");
             columns.Bound(c => c.DisplayName).ClientHeaderTemplate("Description");
             columns.Bound(c => c.IEC).ClientHeaderTemplate("IEC");
             columns.Bound(c => c.Active)
                 .ClientTemplate("#if(Active) {# <i class='fas fa-check'></i>  # } else {# <i class='fas fa-times'></i> #} #")
                 .ClientHeaderTemplate("Active")
                 .HtmlAttributes(new { @class = "text-center" })
                 .Width(100);
         })
         .Pageable(pageable => pageable
             .Refresh(true)
             .PageSizes(true)
             .ButtonCount(5))
         .Sortable()
         .Filterable()
         .Groupable()
         .NoRecords(n => n.Template("<p>There are no records to display.</p>"))
         .HtmlAttributes(new { style = "width:100%;" })
         .Selectable(selectable => selectable
             .Mode(GridSelectionMode.Single)
             .Type(GridSelectionType.Row))
         .Events(events => events
             .Change("lu.onChange")
         )
         .Pageable(p =>
         {
             p.PageSizes(new[] { 5, 10, 30, 50, 100 });
         })
         .DataSource(dataSource => dataSource
             .Ajax()
             .Group(g => g.Add(x => x.IEC))
             .PageSize(50)
             .ServerOperation(false)
             .Read(r => r.Action("RefreshCompetenciesGridData", "ReportLookup").Data("lu.sendAntiForgery"))
         )
    )

I have a partial that has a sortable element in it also as below.
    @(Html.Kendo().Sortable()
              .For($"#{@Model.GridId}")
              .Filter("table > tbody > tr")
              .Cursor("move")
              .PlaceholderHandler("sg.placeholder")
              .ContainerSelector($"#{Model.GridId} tbody")
              .Events(events => events.Change("sg.onChange"))
    )

The sortable element works great, the majority of the time.
When performing a re-order, opening a kendo window and performing a save action the grid is refreshed with the updated data in a TypeScript class as per code below.
    save = (model: any) => {
    var _self = this;
   
    var girdOrderArray = new Array();
   
    if ($("#grid-reorder-warning").length && $("#grid-reorder-warning").is(":visible")) {
        var grid = $("#" + this.girdName).data("kendoGrid");
        var dataItems = grid.dataItems() as any;
        $.each(dataItems,
            (idx: number, dataItem) => {
                var di = idx + 1;
                var id = dataItem.id === undefined ? dataItem.Id : dataItem.id; // Changing the display order appears to also change the dataItem from Id to id.
                girdOrderArray.push({ Id: id, DisplayOrder: di });
            });
   
    }
   
    var da = new Tmsp.AjaxDataAccessLayer(Tmsp.Enums.AjaxCallType.Post,
        Tmsp.Enums.AjaxDataType.Json,
        this.saveUrl,
        JSON.stringify(model),
        "application/json; charset=utf-8",
        { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
        true, true);
   
    da.ajaxCall(data => {
   
        _self.closeWindow();
       
  if ($("#grid-reorder-warning").is(":visible")) {
            grid.dataSource.read().then(() => {
                var dataItems = grid.dataItems();
                var arr = new Array() as any;
                $.each(dataItems,
                    (idx, dataItem: any) => {
                        var id = dataItem.Id === null ? dataItem.id : dataItem.Id;
                        var gridOrderObj = jQuery.grep(girdOrderArray,
                            function (gridOrderObj: any) { return gridOrderObj.Id == id });
                        dataItem.set("DisplayOrder", gridOrderObj[0].DisplayOrder);
                    });
                grid.dataSource.sort({ field: "DisplayOrder", dir: "Desc" });
            });
        } else {
            _self.refreshGrid();
        }
   
        return false;
   
    }, (xhr, status, errorThrown) => {
        console.log(xhr);
        console.log(status);
        console.log(errorThrown);
    });
   
    return false;
    } 

This saves, and reorders teh grid accordingly by the DisplayOrder which is great and what I need. However, when I try and reorder anything else after this the reordered item gives me the new index, but isnt actually changed on the grid.
However, if I refresh the grid through other means, the re-oredering works perfectly.

So, my question, as I need to keep the display order as is prior the the save, how do I acheive this.

Things I have tried
 - Updating the display order on the refreshed gird - suspected cause of the problem.
 - Created a new controller that returns the partial and inisialises the control again -  No effect
 - Resetting the uid (not a preferred option, but thought I would try and see if it was uid) specific. - No effect




 


Simon
Top achievements
Rank 1
 answered on 13 Sep 2019
2 answers
1.1K+ views

Is there a way to display a customized message when the dataSource bound to a DDL TagHelper is empty?

 

Laurie
Top achievements
Rank 1
Iron
 answered on 12 Sep 2019
2 answers
125 views

Hi,

  I am using ImageBrowser as a standalone widget without Editor.

<div>
                    @(Html.Kendo().PanelBar()
                        .Name("panelbar")
                        .ExpandMode(PanelBarExpandMode.Multiple)
                        .Events(events => events
                                .Expand("onExpand")
                            )
                        .Items(panelbar =>
                        {
                            panelbar.Add().Text("Image Browser")
                                .Expanded(false)
                                .Content(@<div id="imgBrowser"/>);
                        })
                    )
</div>
 
<script>
    $("#imgBrowser").kendoImageBrowser({
        transport: {
            type: "imagebrowser-aspnetmvc",
            read: "/ImageBrowser/Read",
            destroy: {
                url: "/ImageBrowser/Destroy",
                type: "POST"
            },
            create: {
                url: "/ImageBrowser/Create",
                type: "POST"
            },
            imageUrl: "@Url.Content("~/shared/UserFiles/Images/{0}")",
            thumbnailUrl: "/ImageBrowser/Thumbnail",
            uploadUrl: "/ImageBrowser/Upload",
        },
        change: insertImagePath
    });
</script>

 

When the PanelBar is expanded & ImageBrowser is loaded, the file icon is missing. Please see the attached picture.

Can you let me know how to display the file icon?

Joel
Top achievements
Rank 1
Iron
 answered on 12 Sep 2019
1 answer
151 views

I am migrating things from the "forms" world to more and more Core based projects.  I keep hitting an a wall which seems to boil down to missing documentation.  Can someone point me in the correct direction?

My needs start with the basic need to configure the layout of a given form for the user upon initial display.  They will make various selections and press the infamous "update" button when done.  In the broadest sense of things I need to do something like:

panelbar.items[0].expanded = true;
panelbar.items[1].expanded = false;

 

That looks simple.  I have figured out how to get the Id of the panel control and have a valid object.  For the life of me I cannot find anything that documents how to find/use the items object.  I know it exists but how of find the item at index "x" seems beyond me.  Based upon the documentation I have found it seems I must find a reference to the item at index "x", then set its expanded property to true/false.  Since I cannot find the index, I am up a creek without the paddle.

I would appreciate any pointers someone can send my way.

 

On the positive side:  My conversion activities have shown me the power of the telerik core tools.  My initial thoughts has some misgivings however experience has shown they are surprisingly powerful.  I am amazed with the amount of code being replaced by what is now standard functionality.  Working with a framework, as opposed to against it, is a simple but important concept to learn.  Kudos to the Telerik/Progress team.

 

 

Aleksandar
Telerik team
 answered on 11 Sep 2019
2 answers
188 views

Hello,

 

I have a signalr bound grid. The grid has custom popup editor with Tabstrip. First tab - upload picture, or show picture based on ImageUrl field of currently edited record.

So, I'm trying to access:

 - @Model.ImageUrl  - it throws null exception and breaks the page overall, or

- @Html.ValueFor(model=>model.ImageUrl) - it is always null, but I'm sure there are values in database

I have tried the same, just to test it, with for example Firstname field from the same model - the same result

@Html.LabelFor(model=>model.ImageUrl) and @Html.EditorFor(model=>model.ImageUrl) work fine, I can see the label and the correct value inside a textbox.

<div class="row">
            <div>
                @Html.ValueFor(model => model.Firstname) @*this is always null, but I need a value*@
            </div>
            <div>
              @* @Model.Firstname  this breaks whole page with null exception*@
            </div>
            <div>
                @Html.EditorFor(model => model.Firstname) @*this works correctly*@
            </div>
        </div>

 

/////////// below is the code, why I need the value

<div id="pictures" class="picture dropZoneElement">
                @if (Html.ValueFor(model => model.ImageUrl) != null)
                {
                    <div class="k-edit-label">
                        <img src="Files/Images/" + @Html.ValueFor(model => model.ImageUrl) />
                    </div>
                }
                else
                {
                    <div class="textWrapper">
                        <p><span>+</span>Add Image</p>
                        <p class="dropImageHereText">Drop image here to upload</p>
                    </div>
                }
            </div>

 

Kind regards

DC

 

Viktor Tachev
Telerik team
 answered on 11 Sep 2019
1 answer
182 views

I noticed in one of my forms that suddenly a validation message appears for a dropdownlist. The message could not be found in kendo.messages.xx-XX.js nor was it a validation message from ASP.NET Core (I use my own, localized form of "Required" etc.attribute messages). I found the message inside the file "Exceptions.resx" in the source of Kendo MVC:

<data name="ValueNotValidForProperty" xml:space="preserve">
  <value>The value '{0}' is invalid.</value>
</data>

How can I translate this into another language?

Regards
Heiko

Nikolay
Telerik team
 answered on 10 Sep 2019
3 answers
392 views

Hello,

I am experiencing a problem applying culture to the validation messages in my editable grid. I experience the exact same problem as in the following demo:  https://demos.telerik.com/aspnet-core/grid/globalization?culture=fr-FR

 

As a user I would expect the validation message to be localized but they don't seem to be.

To reproduce,

  1. Set the culture to anything other then english,
  2. Edit a row,
  3. Empty the "Name" column,
  4. click out of the textbox to activate validation and notice that the validation message displayed is in english.

 

Any help on this will be greatly appreciated!

Thank you

Tsvetomir
Telerik team
 answered on 10 Sep 2019
1 answer
1.0K+ views

I create a disabled DropDownList with the following code:

<kendo-dropdownlist for="FreezeVM.Year" class="form-control"
                    datatextfield="Text"
                    datavaluefield="Value"
                    height="290"
                    enable="false"
                    bind-to="Model.YearList">
</kendo-dropdownlist>

Based on another DropDownList I change the value of this list:

function onTargetTypeChange(e) {
    var targetValue = this.value();
    var currentYear = new Date().getFullYear();
    var yearDrop = $("#FreezeVM\\.Year").data("kendoDropDownList");
    if (targetValue === "6" || targetValue === "7") {
        yearDrop.value(currentYear + 1);
    }
    else {
        yearDrop.value(currentYear);
    };
};

 

The change is reflected on the UI, but not on the underlying Model which still has the old value. As soon as I enable the DropDownList everything works fine. What I expect is that the value gets changed no matter if the dropdown is enabled or disabled.

Regards
Heiko

 

Petar
Telerik team
 answered on 09 Sep 2019
3 answers
834 views

Hi,

i am using ASP.NET Core with a KENDO Grid which calls a Razor Page handler.

For performance reasons, the Grid is pageable, filterable and sortable.

Now we want the DataSourceRequest on the server to directly filter the MongoDB query. I am using "AsQueryable()" on the IMongoCollection, which i thought works nicely with the KENDO DataSourceResult method. 

But the speed of the MongoDB query is always slow. It does not matter if i filter the grid for just one result or if i display all results (paged).

 

Is this the correct way to use KENDO Grid with MongoDB "database-filtering"?

 

I am using the following code:

Client

@(Html.Kendo().Grid<PolicyAudit>().Name("PolicyGrid")
            .Pageable()
            .Navigatable()
            .Sortable()
            .Filterable()
            .Columns(columBuilder =>
            {
                columBuilder.Bound(x => x.Orga);
                columBuilder.Bound(x => x.Operation);
                columBuilder.Bound(x => x.Ressource);
                columBuilder.Bound(x => x.TimeStamp);
                columBuilder.Bound(x => x.UserEmail);
                columBuilder.Bound(x => x.AccessResult);
            })
            .DataSource(source => source.Ajax()
                .Read("PolicyOverview", "Policy", new { handler = "ReadPolicyAudits" })))

 

Server

public async Task<IActionResult> OnPostReadPolicyAudits([DataSourceRequest]DataSourceRequest request)
        {
            var access = new PolicyDataAccess();
            var col = access.GetCollection<PolicyAudit>("MetaPolicyCollection");
 
            var data = await col.AsQueryable().ToDataSourceResultAsync(request);
            return new JsonResult(data);
        }
Tsvetomir
Telerik team
 answered on 09 Sep 2019
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?