Telerik Forums
UI for ASP.NET MVC Forum
2 answers
2.2K+ views

We have a number of pages that execute a common javascript function that sets the first kendo control to have focus.  When the first control is a text box all browsers are setting focus when the page loads.  When the first control is a dropdownlist, IE works but Chrome and FireFox (FF) are not setting the focus to the dropdownlist.  Here is the javascript for the focus.

$(document).ready(function () {
    focusFirstElement(formId);
});
function focusFirstElement(formId) {
    $(formId).find('.editor-control:visible:enabled:not([readonly]):first').focus().select();
}

It seems that the dropdownlist input tag is styled to "display: none" which I could see then why Chrome and FF do not find the control with the current jquery selector (not sure why IE works).  Currently our solution is to have every page set the focus to the desired control, but we were looking for a common javascript to set the focus to first control that is enabled, visible, and not read only.

Any ideas?  Is this possible with the kendo controls?

Thomas
Top achievements
Rank 1
 answered on 13 Sep 2019
5 answers
931 views

I have popup edit mode enabled for my grid. Instead of using the native edit command button, I implemented row click to fire the edit command.
This works and the popup with my custom template shows. However, when I make changes to the data and click the Update button, the window closes, but the data doesn't get updated. My action in the controller is never hit.  I then tried attaching to the Save event then calling a javasript method, but not sure how to persist data from there.

@section Scripts{
    <script type="text/javascript">
        function onChange(e) {
            var grid = e.sender;
            var currentDataItem = grid.dataItem(this.select());                          
           grid.editRow(currentDataItem);             
        }
 
        function onSave(e) {
            var grid = e.sender;
            var currentDataItem = grid.dataItem(this.select());
            alert(currentDataItem["Details"]);
            // what to do here to persist changes??
        }
    </script>
}

 

@Html.Kendo().Grid(Model.Notes).Name("PermitNotes").DataSource(dataSource => dataSource.Ajax().Model(model => model.Id("LCARSKey"))
            .Update(update => update.Action("PermitNotes_Update""Permits"))
            .Read(read => read.Action("Sorting_PermitNotes_Read""Permits"))
            .Destroy(update => update.Action("PermitNotes_Delete""Permits"))
            .Create(create => create.Action("PermitNotes_Create""Permits"))).Columns(columns =>
        {
  
            columns.Command(cmd => { cmd.Destroy(); }).Width("50px");
            columns.Bound(p=>p.Details);
            columns.Bound(p => p.Name).Title("User");
            columns.Bound(p => p.DateCreated).Title("Date");
  
        }).Sortable(sortable => sortable.AllowUnsort(false)).Selectable(selectable => selectable.Mode(GridSelectionMode.Single).Enabled(true)
            .Type(GridSelectionType.Row)).ToolBar(toolbar => {toolbar.Custom().Text(@Html.IconEmoji("arrowLeft1").ToString()).Url("javascript:window.history.back();").HtmlAttributes(new {title="Go Back."}); toolbar.Create().Text("Add New Note").IconClass("").HtmlAttributes(new {hexkey=@Model.LcarsPermit.ObjectKey.ToHexKey()});
  
            }).Editable(e=> { e.Mode(GridEditMode.PopUp);e.TemplateName("PermitNote");e.Enabled(true);}).Events(ev=> { ev.Change("onChange");ev.Save("test");
            })

 

Here is my custom template, only only one input

 

<html><head>     <meta name="viewport" content="width=device-width" />     <title>PermitNote</title>     <style type="text/css">         A.k-primary {
            color: #FFF !important;
        }
    </style></head><body>     <div class="m-3">         <div class="float-left mr-2">Details: </div>         <div class="float-left">@Html.TextArea("Details", new { style = "width:250px;", rows = "3", cols = "100" })</div>     </div></body></html>
Mbott
Top achievements
Rank 1
 answered on 13 Sep 2019
1 answer
3.6K+ views
I am new to mvc, new telerik. I have page with several sections: section A to G, and a button to register.
Section A contains an Asp.Net MVC Grid.
I would like to save this data to db only after filling all the sections. However I should be able to save the section A data in grid to the associated viewmodel each time a row is added, updated, deleted. I have tried below code as per samples provided on the telerik website, but I am unsuccessful. Please could you help me on how will be be able to achieve this?

My object model for the page looks like below:

namespace SampleProject.Models
{
public class Base {
public Guid Id {get; set;}
public string Name{get; set;}
}
public class Person : Base {
public string TelephoneNumber {get; set;}
public string FaxNumber {get; set;}
public string EmailAddress {get; set;}
}
public class Order {
public Order()
{
Persons = new List<Person> ();
}
public List<Person> Persons {get; set;}
}

}

namespace SampleProject.ViewModels
{
public class RegisterViewModel
{
public RegisterViewModel()
{
Order = new Order();
}
    Order Order {get; set;}
}
}

VIEw:
@model SampleProject.ViewModels.RegisterViewModel
 @(Html.Kendo().Grid<SampleProject.Models.Person>()
                                    .Name("PersonGrid")
                                    .Columns(columns =>
                                    {
                                        columns.Bound(c => c.Name);
                                        columns.Bound(c => c.TelephoneNumber).Title("Telephone Number");
                                        columns.Bound(c => c.FaxNumber).Title("Fax Number");
                                        columns.Bound(c => c.EmailAddress).Title("Email Address");
                                        columns.Command(command =>
                                        {
                                            command.Edit();
                                            command.Destroy();
                                        }).Title("Actions").Width(250);
                                    })
                                    .ToolBar(toolbar => toolbar.Create())
                                    .Editable(editable => editable.Mode(GridEditMode.InLine))
                                    .HtmlAttributes(new { style = "height: 150px;" })
                                    .Scrollable()
                                    .Sortable()
                                    .DataSource(dataSource => dataSource
                                                .Ajax()
                                                .Model(model => model.Id(c => c.Id))
                                                .Create(create => create.Action("CreatePerson", "Register"))
                                                .Update(update => update.Action("UpdatePerson", "Register"))
                                                .Destroy(delete => delete.Action("DeletePerson", "Register"))
                                                .Read(read => read.Action("ReadPersons", "Register"))
                                                )
                                )

Controller:
public class RegisterController
{
private RegisterViewModel registerViewModel;
public ActionResult RegisterNewOrder()
        {           
            return View(registerViewModel);
        }

public ActionResult ReadPersons([DataSourceRequest] DataSourceRequest request)
        {
            return Json(registerViewModel.Order.Persons.ToDataSourceResult(request),
                        JsonRequestBehavior.AllowGet);
        }

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CreatePerson([DataSourceRequest] DataSourceRequest request, Person person)
        {
            if (person != null)
            {
                person.Id = Guid.NewGuid();
                if (ModelState.IsValid)
                {
                    var xPerson = new Person
                    {
                        Id = person.Id,
                        Name = person.Name,
                        TelephoneNumber = person.TelephoneNumber,
                        EmailAddress = person.EmailAddress,
                        FaxNumber = person.FaxNumber
                    };
                    registerViewModel?.Order?.Persons.Add(xPerson);
person.Id = xPerson.Id;
                }
            }
            return Json(new[] { person }.ToDataSourceResult(request, ModelState));
        }

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult UpdatePerson([DataSourceRequest] DataSourceRequest request, Person person)
        {
            if (ModelState.IsValid)
            {
                var xPerson = registerViewModel.Order.Persons
                                       .FirstOrDefault(x => x.Id == person.Id);
                //TODO: Need to find out exact
                if (xPerson  != null)
                {
                    xPerson .Name = person.Name;
                    xPerson .TelephoneNumber = person.TelephoneNumber;
                    xPerson .FaxNumber = person.FaxNumber;
                    xPerson .EmailAddress = person.EmailAddress;
                }
            }
            return Json(new[] { person }.ToDataSourceResult(request, ModelState));
        }
[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult DeletePerson([DataSourceRequest] DataSourceRequest request, Person person)
        {
            if (person != null && ModelState.IsValid)
            {
                registerViewModel?.Order?.Persons.Remove(person);
            }
            return Json(new[] { person }.ToDataSourceResult(request, ModelState));
        }
}

Thanks,
Sreeni

Boyan Dimitrov
Telerik team
 answered on 13 Sep 2019
1 answer
306 views

I have a Grid with a custom popup editor. Inside the popup editor, I have a MultiColumnComboBox.

 

When I select a value in the MultiColumnComboBox and click Update button in the editor, the Update method does not get fired. When I console out e.model on the save event, dirty flag is false, dirtyFields is empty and contact_id is null.

 

@Html.LabelFor(model => model.contact_id)
@(Html.Kendo().MultiColumnComboBoxFor(model => model.contact_id)
                .AutoBind(false)
                .Placeholder("Select Contact...")
                .DataTextField("contact_number")
                .DataValueField("id")
                .Columns(columns =>
                {
                    columns.Add().Field("contact_number").Title("Id");
                    columns.Add().Field("contact_name").Title("Name");
                })
                .Filter(FilterType.Contains)
                .DataSource(source =>
                    {
                        source.Read(read =>
                            {
                                read.Action("SearchContact", "Manager").Data("getContactData").Type(HttpVerbs.Post);
                            })
                            .ServerFiltering(false);
                    })
                )
Viktor Tachev
Telerik team
 answered on 13 Sep 2019
1 answer
109 views

I am pretty new to MVC/Telerik and am having an issue populating a grid. I created the standard Telerik MVC5 project with the Grid and menu. I added my model, created a context and updated the controllers and views. When i run the app on the Visual Studio IIS Express instance i have zero issues. However, once i publish it to an IIS 8 test server i receive HTTP 500 errors and an empty grid.Looking at the Fiddler results it appears that the read function on grid is the issue.

 

Grid Controller

public partial class GridController : Controller
{   
        public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
        {         
            using (var ctx = new CWDataContext())
            {
                IQueryable<CWDataModel> carts = ctx.CW_Data;
                DataSourceResult result = carts.ToDataSourceResult(request);
                return Json(result);
            }
        }
}

 

Home Controller

 public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();
        }
    }

 

Model

   [Table("CWCartLblFile")]
    public class CWDataModel
    {
        [Key]
        public int Row_ID { get; set; }
        public string COLOR { get; set; }
        public string SKU { get; set;

    }

 

Context

public class CWDataContext : DbContext
    {
        public CWDataContext() : base("defaultString")
        {            
        }
        public DbSet<CWDataModel> CW_Data {get; set;}
}

 

Index View

<div class="row">
    <div class="col-12">
        @(Html.Kendo().Grid<TelerikMvcApp1.Models.CWDataModel>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(product => product.COLOR).Width(50);
                columns.Bound(product => product.SKU).Width(50);
            })
            .Pageable()
            .Sortable()
            .Scrollable()
            .Filterable()
            .HtmlAttributes(new { style = "height:550px;" })
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(20)
                .Read(read => read.Action("Orders_Read", "Grid"))
            )
        )
    </div>
</div>

 

I am not sure if something in the code is incorrect or i overlooked something on the web server.

 

Mark A
Top achievements
Rank 2
 answered on 12 Sep 2019
2 answers
94 views

After upgrading to UI for ASPNET MVC 2019.2.619, default values defined in the grid's datasource section are no longer populating. This was working in a previous version.  Now when clicking the new button, the fields are blank.  Below is just an example.  No code was changed from the previous version.  This is for pop-up editing with a template.  Any help would be appreciated.

 

.Model(model =>
 {
     model.Id(m => m.TruckKey);
     model.Field(f => f.DriverName).DefaultValue("Driver Name");
 })
Tsvetomir
Telerik team
 answered on 12 Sep 2019
8 answers
621 views

Hi,

I have a standard grid with a NumericTextBoxFor field using inline editing in a MVC5 project.

The NumericTextBoxFor is configured to show 5 digits after the decimal separator in both the editor-template and the HTML code.

The problem is, that the 5 digits is only shown if the NumericTextBoxFor is selected when in edit mode or if not in edit mode at all - otherwise only 2 rounded digits is shown.

Any idea ?

I have a proof-of-concept to show, if this is new to you.

Thank you in advance.

Brian
Top achievements
Rank 1
 answered on 11 Sep 2019
1 answer
265 views

Hello

I am searching for example usage of the Telerik controls to create a user interface for a one-to-many relationship.

For example, a form for an Invoice; and the lower portion of the form has a grid for the user to create multiple line items.

This is a common UI, but I'm unable to find anything. Any help is appreciated.

 

Thanks!

Petar
Telerik team
 answered on 10 Sep 2019
1 answer
86 views

Hi

 

I am having an issue with the grid. I am using GridEditMode.PopUp. If I click create to open the PopUp and then press cancel, it inserts a blank row into the grid

Viktor Tachev
Telerik team
 answered on 10 Sep 2019
1 answer
407 views

Before version 2019.2 I used MobileSwitch for checkboxes and when I want to clear a form I did this:

1._form.reset();
2.$(_form).find("[type=checkbox]").each(function () {
3.      $("#" + this.id).data("kendoMobileSwitch").refresh();
4.})

 

Now, using Switch, I've changed line 3 to

$("#" + this.id).data("kendoSwitch").refresh();

but that didn't work.

 

How can I achieve the same with new Switch?

Ezequiel
Top achievements
Rank 2
 answered on 09 Sep 2019
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
Upload
ComboBox
MultiSelect
Window
ListView
TabStrip
Menu
Installer and VS Extensions
Spreadsheet
AutoComplete
TreeList
Gantt
PanelBar
NumericTextBox
Filter
ToolTip
Map
Diagram
Button
PivotGrid
Form
ListBox
Splitter
Application
FileManager
Sortable
Calendar
View
MaskedTextBox
PDFViewer
TextBox
Toolbar
MultiColumnComboBox
Dialog
DropDownTree
Checkbox
Slider
Switch
Notification
ListView (Mobile)
Pager
Accessibility
ColorPicker
DateRangePicker
Wizard
Security
Styling
Chat
MediaPlayer
TileLayout
DateInput
Drawer
SplitView
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Template
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Rating
ScrollView
ButtonGroup
CheckBoxGroup
Licensing
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
Localization
MultiViewCalendar
PopOver (Mobile)
Ripple
ScrollView (Mobile)
Switch (Mobile)
PivotGridV2
FlatColorPicker
ColorPalette
DropDownButton
AIPrompt
PropertyGrid
ActionSheet (Mobile)
BulletGraph
Button (Mobile)
Collapsible
Loader
CircularGauge
SkeletonContainer
Popover
HeatMap
Avatar
ColorGradient
CircularProgressBar
SplitButton
StackLayout
TimeDurationPicker
Chip
ChipList
DockManager
ToggleButton
Sankey
OTPInput
ChartWizard
SpeechToTextButton
InlineAIPrompt
TimePicker
StockChart
RadialGauge
ContextMenu
ArcGauge
AICodingAssistant
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?