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

Hello,

I'm having a strange problem with a cascading dropdown. I have an in cell edit grid for a list in my model. I have two dropdowns in editor templates. CustomerContact cascades from Customer. Both dropdowns are bound to a SelectListItem object on my model with properties "Text" and "Value". Both dropdowns function normally on initial selection and the value of both dropdowns is successfully set as an object. I'm able to use #= data.Text # in a ClientTemplate to display the text of the selected item.

This is where it gets weird. If I click to focus the cell containing my cascaded CustomerContact dropdown, and then click off without actually expanding the dropdown, the value changes from being the whole object to just the DataValueField ("Value" in my case). I've checked and sure enough the datasource change event is triggered when i click off of the cell for the CustomerContact dropdown even though I haven't opened it. This doesn't happen to the Customer dropdown, so it must be something with the cascade but I really can't understand what is causing it. Code below and some screenshots of before and after click my second dropdown's cell. Any help would be appreciated!

Grid:

@(Html.Kendo().Grid(Model.ScheduledInteractions)
     .Name("scheduled-interactions-grid")
     .DataSource(dataSource => dataSource
          .Ajax()
          .Model(model =>
           {
                    model.Id(p => p.Id);
                    model.Field(p => p.Customer).DefaultValue(new SelectListItem() { Text = "- Select -", Value = "-1" });
                    model.Field(p => p.CustomerContact).DefaultValue(new SelectListItem() { Text = "- Select -", Value = "-1" });
             })
            .ServerOperation(false))
            .Columns(c =>
            {
                c.Command(cmd => cmd.Destroy()).Width(100);
                c.Bound(x => x.Customer).EditorTemplateName("CustomerDropdown")
                    .ClientTemplate("#= data.Customer ? data.Customer.Text : '' #" +
                    "<input type='hidden' name='ScheduledInteractions[#= getIndex(data)#].Customer' value='#= data.Customer #' />"
                );
                c.Bound(x => x.CustomerContact).EditorTemplateName("CustomerContactDropdown")
                .ClientTemplate("#= data.CustomerContact ? data.CustomerContact.Text : '' #" +
                    "<input type='hidden' name='ScheduledInteractions[#= getIndex(data)#].CustomerContact' value='#= data.CustomerContact #' />"
                );
                c.Bound(x => x.InteractionType).EditorTemplateName("InteractionTypeDropdown")
                .ClientTemplate("#= InteractionType #" +
                    "<input type='hidden' name='ScheduledInteractions[#= getIndex(data)#].InteractionType' value='#= InteractionType #' />"
                );
                c.Bound(x => x.Description).ClientTemplate("#= Description #" +
                    "<input type='hidden' name='ScheduledInteractions[#= getIndex(data)#].Description' value='#= Description #' />"
                );
            })
            .ToolBar(tb => {
                tb.Create();
            })
            .Navigatable()
            .Editable(editable => editable.Mode(GridEditMode.InCell))
        )

Editor Templates:

@model SelectListItem
    @(Html.Kendo().DropDownListFor(m => m)
        .Name("customer-select")
        .HtmlAttributes(new { @class = "form-control", name = Html.NameFor(m => m) })
        .OptionLabel("- Select -")
        .DataTextField("Text")
        .DataValueField("Value")
        .Filter("contains")
        .DataSource(ds =>
        { 
            ds.Read(read =>
            {
                read.Action("CompanyOptions", "Common", new { Area = "API" }).Data("filterCustomersInGrid");
            }).ServerFiltering(true);
        })
    )
    @Html.ValidationMessageFor(m => m, "", new { @class = "text-danger" })
@model SelectListItem
    @(Html.Kendo().DropDownListFor(m => m)
        .Name("customer-contact-select")
        .HtmlAttributes(new { @class = "form-control", name = Html.NameFor(m => m) })
        .OptionLabel("- Select -")
        .DataTextField("Text")
        .DataValueField("Value")
        .Filter("contains")
        .DataSource(ds => 
        { 
            ds.Read(read => 
            {
                read.Action("ContactOptions", "Common", new { Area = "API" }).Data("filterContactsInGrid");
            }).ServerFiltering(true);
        })
        .AutoBind(false)
        .CascadeFrom("customer-select")
    )
@Html.ValidationMessageFor(m => m, "", new { @class = "text-danger" })

Javascript:

function getCurrentGridRow() {
    var grid = $("#scheduled-interactions-grid").data("kendoGrid");
    var editRow = grid.tbody.find("tr:has(.k-edit-cell)");
    return grid.dataItem(editRow);
}

function filterCustomersInGrid() {
    var row = getCurrentGridRow();
    return { contains: '', currentId: row.Customer ? row.Customer.Value : null };
}

function filterContactsInGrid() {
    var row = getCurrentGridRow();
    return { companyId: row.Customer ? row.Customer.Value : null, contains: '', currentId: row.CustomerContact ? row.CustomerContact.Value : null };
}

function getIndex(dataItem) {
    var data = $("#scheduled-interactions-grid").data("kendoGrid").dataSource.data();
    return data.indexOf(dataItem);
}

Value of Dropdowns After Initial Selections

After Cell Click:


Sarah
Top achievements
Rank 1
 updated question on 19 Jan 2022
0 answers
245 views

Hi guys,

we been using Kendo version 2020.1.406.545. is it a must to upgrade to the latest?

kind regards

Tony

Tony
Top achievements
Rank 2
Iron
Iron
Iron
 asked on 19 Jan 2022
1 answer
342 views

I am attempting to keep the Gantt Chart editable, but remove the ability to create new tasks/child entries.

 

I have tried adding this CSS and it did not work:

  .k-gantt-actions .k-button {
            visibility: hidden;
        }

The button still shows.

 

Any help?

Yanislav
Telerik team
 answered on 19 Jan 2022
1 answer
123 views
In the grid control I want to do GridFilterMode.Row filtering but to increase performance I want to remove the auto complete and default filtering.  How can I disable that option and just make it a manual filter only?
Eyup
Telerik team
 answered on 19 Jan 2022
1 answer
314 views

We've added the Telerik.UI.for.AspNet.Mvc4.2021.3.1207 NuGet package to our project and I was wondering what the best practices are for excluding unneeded content from publishing. There is a folder called 2021.3.1207-source which by default is published with all the other content that the NuGet package has added. So far we have manually marked the content to not be included when published in our build pipelines, but we're wondering if there is a more standard way of doing this? Is there a NuGet package which excludes the source folder?

In addition to this, is there a preferred method of excluding themes from a project? Again we can manually remove them or mark them to not be published, but I was wondering if there is a suggested way to configure what is and isn't included.

Many thanks

Ivan Danchev
Telerik team
 answered on 19 Jan 2022
1 answer
119 views
I'm using a kendo UI grid for MVC and I've managed to create a dropdown for a field in the grid using an editor template.  The only problem is that the drop-down does not default to the value that is currently in the field. Can someone explain how to do this or point me to a demo? Thanks.
Eyup
Telerik team
 answered on 18 Jan 2022
0 answers
93 views

I have a grid, with in-cell editing where only one field is editable, which is a foreign key field with a dropdown list. The grid is set to autosync, and batch mode is off.

This works fine, updating the records after an option is selected from the dropdown list. However, on the server-side I have implemented some consistency checks, to see if a user updates a record after it has been updated by another user, but before their grid was refreshed. This works, and I can get an error message displayed.

However, what I need to happen once an error occurs, is for the record to be reset back to its original state. At the moment, the selected item on the dropdown list is shown, along with a dirty flag.  I have tried calling a datasource read on the grid, but this isn't called.

How can I reset the grid after an error?

The code is :-

    @(Html.Kendo().Grid<RightToResideAudit.Models.RightToResideList>()
                     .Name("Grid")
                     //.Events(e => e.Edit("onEdit"))
                     .Columns(col =>
                     {
                         col.Bound(o => o.ID).Title("ID");
                         col.Bound(o => o.PatientID).Title("Patient ID");
                         col.Bound(o => o.PatientName).Title("Patient Name");
                         col.Bound(o => o.Site).Title("Site");

                     
                         col.ForeignKey(p => p.ReasonID, (System.Collections.IEnumerable)ViewData["reasons"], "ID", "Reason")
         .Title("Reason").Width(250);



                         //col.Command(command => { command.Edit(); command.Destroy(); });

                     })

                        .Editable(editable => editable
                         .Mode(GridEditMode.InCell))
                         .DataSource(ds => ds
                         .Ajax()
                         .Events(events => events.Error("errorHandler"))
                         .AutoSync(true)
                         .Batch(false)

                         .Model(m =>

                         { m.Id(p => p.ID);
                             m.Field(p => p.ID).Editable(false);
                             m.Field(p => p.PatientID).Editable(false);
                             m.Field(p => p.PatientName).Editable(false);
                             m.Field(p => p.Site).Editable(false);
                             m.Field(p => p.Ward).Editable(false);
                             m.Field(p => p.BedSpace).Editable(false);
                             m.Field(p => p.CurrentLOS).Editable(false);
                             m.Field(p => p.LOSGroup).Editable(false);
                             m.Field(p => p.Pathway).Editable(false);
                             m.Field(p => p.LastFlaggedAsR2R).Editable(false);

                         })
                 //.Events(events => events.Error("error"))
                 .PageSize(15)
                 .Read(rd => rd.Action("RD_RightToResideList", "Home").Data("filter")

                 )
                  .Create(create => create.Action("NA", "Home"))
                 .Update(update => update.Action("UpdateRecord", "Home"))
                 .Destroy(delete => delete.Action("NA", "Home"))
                 )
                  .Pageable(p => p.Refresh(true))
                 .Sortable()
                 .Filterable()
            )



</div>


<script type="text/javascript">

    function filter()
        {
        return {
            AuditNumber: 1
        };

    }


    function errorHandler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });

            var grid = $("#Grid").data("kendoGrid");

            grid.one("dataBinding", function (e) {

                e.preventDefault();   // cancel grid rebind if error occurs
                $("Grid").data("kendoGrid").dataSource.read();



            });
            alert(message);
           
        }
    }
</script>

 

AP
Top achievements
Rank 1
Iron
Iron
Veteran
 asked on 18 Jan 2022
2 answers
129 views

Hello,

 

we would like to know if there is a way to allow the users copy the full value of a number with decimals and not only the value that is visible form the front end (in the following scenarios 13 decimals as you can see from the formula bar and 3 decimals as format).

Below you can see a spreadsheet component in which the numbers displayed are declared as decimals, in the formula bar you can see the real value of the number with 13 decimals, while I've highlighted the cell of interest in the print (cell L25) that as you can see has 3 decimals.

When coping the cell L25 and trying to paste it in the same spreadsheet component (for example S15) the number pasted is formatted the same way of the original cell and in the formula bar I find the same  decimals of the original cell; instead in the moment i try to copy the number in an other spreadsheet component that is in one other page, the pasted number is formatted the same way of the original one, so 3 decimals but I find also just 3 decimals visible from the formula bar instead of the original 13 decimals.

Can you please provide an explanation related to this behavior? How can we arrange that the paste action of values with decimals keep the same format of the original selection and also in the formula bar the same decimals too?

Thanks,

Claudio
Top achievements
Rank 1
Iron
Iron
 answered on 18 Jan 2022
0 answers
128 views

The data is displayed in my nested grid (binds to the main grid's collection property) inside the main grid's editor template. But when I try to add/update the data the editor template is found but not displayed correctly. For some reason it just shows 0 instead of the editor template content. What could be the problem here?

p.s. Found this on the forum:

When you are trying to load a helper that will contain templates in another template (in this case the Popup template of the main Grid), you need to ensure that you are calling the ToClientTemplate method over the nested helpers. This should resolve the escaping in the templates and it should resolve the problem that you are facing

So I've added ToClientTemplate() to my nested grid & tried adding it to the helpers inside the nested grid's popup editor but this changes nothing,the problem is the same.

Valeria
Top achievements
Rank 1
 updated question on 18 Jan 2022
1 answer
334 views
I have this inside my grid popup editor view:

@model App.UI.Web.Models.SuitViewModel

 

@(Html.Kendo().DropDownTreeFor(x => x.subjectid) .Name("subjectsDDT") .HtmlAttributes(new { style = "width: 500px;" }) .DataSource(ds => ds.Read("ReadDropDownTreeSubjects", "BaseDirectory") ) .Placeholder("Select subject...") .Filter("contains") .DataTextField("name") .DataValueField("id") .ValuePrimitive(true) .ClearButton(false) .Events(ev => ev.Select("watch")) )


The subjectid property of SuitViewModel view model must be equal to the id of the item selected in the dropdowntree but i always receive 0 in my controller. Where is the problem here?
Eyup
Telerik team
 answered on 17 Jan 2022
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?