Telerik Forums
UI for ASP.NET MVC Forum
3 answers
496 views

Does anyone have any experience using a Telerik Kendo Grid inside of the BeginCollectionItem HTML helper?

I have a view that lists a number of Users.  Each time you select a user, that user's details (defined inside an Editor Template which contains the Kendo Grid) are populated into a Kendo Panel Bar.  The HTML.BeginCollectionItem extension is being used because you can have "n" number of Users selected at a given time, and I want the user to be able to see multiple Editor Templates at once.

This has worked well for various different controls in the editor template (Kendo Text Boxes, Kendo Combo Boxes, etc.), but the grid is giving us problems.  The grid can display the data just fine, but when you click on a cell to edit its values, a generic Javascript error is thrown: "Uncaught SyntaxError: Unexpected identifier".  If you dig a little deeper, this is the code block that apparently has the problem (which I believe is kendo code):

(function(d<br>/**/) {<br>return (((d.Users || {})[c57d5c44-c352-4935-8cd7-b3ef45a697f2] || {}).Username)<br>})

I believe the issue revolves around how the BeginCollectionItem extension names the controls inside the Editor Template, but I haven't been able to resolve it.  Has anyone seen anything similar?

T. Tsonev
Telerik team
 answered on 10 Mar 2016
1 answer
94 views

Hi,

I have this in my view:

@(Html.Kendo().DatePickerFor(model => model.Date).Min(DateTime.Now).Value(@Model.Date).Events(e => e.Change("updateDatePicker")))

Initially, when you look at the datepicker, it shows you the correct date. But when I click it, it opens with today's date selected instead of the date of my model. For example, the date in my model is july 9th 2016 but when I open the datepicker it opens with march 10th 2016 selected.

I have searched a lot but haven't found a solution. Any help is greatly appreciated.

Baldvin
Top achievements
Rank 1
 answered on 10 Mar 2016
2 answers
825 views

Hello,

 I have a model defined as 

public class Parent
{
        public List<Child> Children { get; set; }  
}

public class Child
{
    property int Id { get; set;}
    property string Name {get; set;}
    property int  Age {get; set;}
}

My goal is to have a grid on my main page whereas the model is the parent and the grid is used to populate the Children list. I do not want the grid to invoke any server method. It should just populate the  Children list. When the parent is saved, I am intending that its Children list will contain the items added within the Parent's POST operation. 

I can create the grid, but I can't seem to get it to add items. When I add the toolBar.Create() option, I get the following error; 

"The Insert data binding setting is required by the insert command. Please specify the Insert action or url in the DataBinding configuration."

But I don't want any insert action to occur on the server. I just want the grid to populate the Children list on the client. 

How can I do this? 


 

Nikolay Rusev
Telerik team
 answered on 10 Mar 2016
1 answer
112 views
Is the Kendo / ASP.NET MVC Spreadsheet control a beta version. From which version was this supported. ?  
Dimiter Madjarov
Telerik team
 answered on 10 Mar 2016
4 answers
192 views

Hi,

     I read many threads about configuring custom popup editor in KendoUI Grid like this one.

http://www.telerik.com/forums/custom-popup-editor-with-additional-fields

I also found how to use a separate html file and use it as a template.  However, I didn't find how to use javascript to access model inside this template.  The answer il always to implement edit event to access model and change behavior.  In my case, fields shown changes depending on many criterias like:  Field 1 ID is 1 or 2 and Field 2 ID is 4 for example.

If it is possible to use AngularJs, it is better :-)

 

Thank you

 

Steve
Top achievements
Rank 1
 answered on 10 Mar 2016
4 answers
1.3K+ views

I can't seem to get a drop down Editor Template working on my grid's popup editor. I am using a ViewModel rather than using my Entity Model directly, maybe that is part of the problem? I cannot use the Model directly as the database schema does not match the expected pattern, and one is supposed to always use a ViewModel I am told.

Here is what I've got:

View Models

The UIHint is added as required and I have the quarter property linked to  the Quarter object per the pattern.

public class AquisitionNotesViewModel
    {
    public int noteid { get; set; }
    public int sourceid { get; set; }
    public int? cyear { get; set; }
 
    [UIHint("QuarterDropDown")]
    public Quarter quarter { get; set; }
 
    [Column(TypeName = "text")]
    public string note { get; set; }
    [Column(TypeName = "date")]
    public DateTime? datetime { get; set; }
    }
 
public class Quarter
{
    public int? quarter { get; set; }
}

Controller

The controller is returning a List of Quarter objects with valid values as well as the ViewModel to populate the grid.

public ActionResult AquisitionNotes_Read([DataSourceRequest] DataSourceRequest request, int sourceid)
        {
            IList<Quarter> quartersList = new List<Quarter>();
            quartersList.Add(new Quarter { quarter = 1 });
            quartersList.Add(new Quarter { quarter = 2 });
            quartersList.Add(new Quarter { quarter = 3 });
            quartersList.Add(new Quarter { quarter = 4 });
 
            ViewData["quarters"] = quartersList;
 
            IList<AquisitionNotesViewModel> notesVM = new List<AquisitionNotesViewModel>();
 
            var Query = from notes in db.acquisitionnotes
                        where notes.sourceid == sourceid
                        select new
                            {
                            noteid = notes.noteid,
                            sourceid = notes.sourceid,
                            quarter = notes.quarter,
                            cyear = notes.cyear,
                            note = notes.note,
                            datetime = notes.datetime
                            };
 
            foreach ( var note in Query) {
                notesVM.Add(new AquisitionNotesViewModel
                {
                    noteid = note.noteid,
                    sourceid = note.sourceid,
                    quarter = new Quarter { quarter = note.quarter },
                    cyear = note.cyear,
                    note = note.note,
                    datetime = note.datetime,
                });
            }
            return Json(notesVM.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);

Editor Template (named QuarterDropDown)

Since I do not have separate values and IDs I set DataValueField and DataTextField to my field (property) name. And I bind to the List of quarters.

@(Html.Kendo().DropDownList()
    .Name("quarter") // Name of the widget should be the same as the name of the property
    .DataValueField("quarter") // The value of the dropdown is taken from the EmployeeID property
    .DataTextField("quarter") // The text of the items is taken from the EmployeeName property
    .BindTo((System.Collections.IEnumerable)ViewData["quarters"]) // A list of all employees which is populated in the controller
)

And finally my Grid

@(Html.Kendo().Grid<AquisitionNotesViewModel>()
    .Name(GridID)
    .Columns(columns =>
    {
        columns.Bound(p => p.datetime ).Format("{0:dd/MM/yyyy}");
        columns.Bound(p => p.quarter.quarter ).Width(120);
        columns.Bound(p => p.cyear).Width(50);
        columns.Bound(p => p.note).Width(120);
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:350px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(10)
        .Sort(sort => sort.Add("datetime").Ascending())
        //.Events(events => events.Error("error_handler"))
        .Model(model => model.Id(p => p.noteid ))
        .Create(update => update.Action("AquisitionNotes_Create", "AquisitionNotes"))
        .Read(read => read.Action("AquisitionNotes_Read", "AquisitionNotes").Data("GetCurrentSourceID"))
        //.Read(read => read.Action("AquisitionNotes_Read", "AquisitionNotes", new { sourceid = 383}))
        .Update(update => update.Action("AquisitionNotes_Upodate", "AquisitionNotes"))
        .Destroy(update => update.Action("AquisitionNotes_Destroy", "AquisitionNotes"))
    )
)

What am I missing or doing wrong?

Thanks, Brad

 

Brad
Top achievements
Rank 1
 answered on 09 Mar 2016
1 answer
284 views

Hi,

I currently filter my grid using a kendo dropdown box, that's all fine and it works well.  I have a requirement here to add another dropdown that fitlers the grid data by the dates list but plus additional dates.  For example the dropdown must take a date fromt he grid and add 21 days to it and show only the results for those items.  How can this be accomplished? 

Here is my code for my current filter

function periodChange() {
     var ddl = document.getElementById("dates");
     var value = this.value(),
          grid = $("#Grid").data("kendoGrid");
 
     if (value) {
         grid.dataSource.filter({
             field: "fixture_stop",
             operator: "eq",
             value: ddl.value
         });
     } else {
         grid.dataSource.filter({});
     }
 }

Here is my grid code

@(Html.Kendo().Grid<MyProject.ViewModels.VesselsViewModel>()
           .Name("Grid")
           .Columns(columns =>
           {
               columns.Bound(c => c.vessel_idx).Title("")
                   .ClientTemplate("<div class='status_flags'></div>")
                   .Width(40);
               columns.Bound(c => c.owner_company)
                   .Filterable(filterable => filterable.UI("companyFilter"))
                   .Title("Owner").Width(200);               
               columns.Bound(c => c.fixture_stop)
                   .ClientTemplate("#=fixture_stop ? kendo.toString(kendo.parseDate(fixture_stop), 'dd/MM/yyyy') : '' #")
                   .Title("Off Hire");                
           })
          .Editable(editable => editable.Mode(GridEditMode.InLine))
          .Pageable()
          .Events(e => e.DataBound("prompt"))
          .Sortable(sortable => sortable.AllowUnsort(true)
              .SortMode(GridSortMode.MultipleColumn))
              .Groupable().ToolBar(toolbar =>
              {
                  toolbar
                      .Template(@<text>
 
          <label class="date-label" for="periods">Period:</label>
 
          @(Html.Kendo().DropDownList()
                          .Name("periods")
                          .OptionLabel("All")
                          .DataTextField("Text")
                          .DataValueField("Value")
                          .AutoBind(false)
                          .Events(e => e.Change("periodChange"))
                          .BindTo(new List<SelectListItem>() {
                              new SelectListItem() {
                                  Text = "21 Days"
                                   
                              },
                              new SelectListItem() {
                                  Text = "3 Months"                                                                                            
                              }
                          })
          )</text>);
              })//Toolbar
          .DataSource(dataSource => dataSource
          .Ajax()
          .Events(events => { events.RequestEnd("onRequestEnd"); })
          .Sort(sort =>
              {
                  sort.Add(
                  company => company.owner_company).Ascending();
              })
          .PageSize(40)
          .Model(model =>
              {
                  model.Id(p => p.vessel_idx);                 
              })
        .Read(read => read.Action("vessels_Read", "Home"))
        .Update(update => update.Action("vessels_Update", "Home"))
        ))

What I need to do here is grab the date value from the grid and add 21 to it but I'm not sure how I would do this using my code.  Any help is appreciated. Thanks.

Boyan Dimitrov
Telerik team
 answered on 09 Mar 2016
4 answers
544 views

I have a grid like this:

@(Html.Kendo().Grid<License>()
      .Name("popupGrid")
      .Columns(columns =>
      {
          columns.Bound(p => p.LicenseId).Width(20).Hidden().HeaderHtmlAttributes(new { @title = "License" });
          columns.ForeignKey(p => p.CustomerId, (System.Collections.IEnumerable)ViewData["customers"], "CustomerID", "CustomerName")
            .Title("Customer").Width(200);
          columns.Bound(p => p.VendorId).Width(20).HeaderHtmlAttributes(new { @title = "Vendor" });
          columns.Bound(p => p.ProductId).Width(20).HeaderHtmlAttributes(new { @title = "Product" });
          columns.Command(p => p.Edit().Text("Edit").HtmlAttributes(new { @title = "Edit" })).Width(80);
      })
          .ToolBar(toolbar => toolbar.Create().Text("Add").HtmlAttributes(new { @title = "Add" }))
      .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("PopupEditView"))
      .Events(e => e.Edit("onEdit"))
      .DataSource(dataSource => dataSource
          .Ajax()
          .Model(model => model.Id(p => p.LicenseId))
              .Create(create => create.Action("Create", "Home").Type(HttpVerbs.Post))
              .Read(read => read.Action("Read", "Home").Type(HttpVerbs.Post))
              .Update(update => update.Action("Update", "Home").Type(HttpVerbs.Post))
          )
)

and PopupEditView.cshtml :

@(Html.Kendo().DropDownListFor(m => m.CustomerId).Name("CustomerId")
                  .ValuePrimitive(true)
                  .DataTextField("CustomerName")
                  .DataValueField("CustomerId")
               //.OptionLabel("Select Customer...") 
                  .DataSource(dataSource =>
                  {
                      dataSource.Read(read => read.Action("GetCustomers", "Home"))
                                .ServerFiltering(true);
                  })
            )
            @Html.ValidationMessageFor(m => m.CustomerId)

HomeController : 

[HttpPost]
        public JsonResult Create([DataSourceRequest] DataSourceRequest request, License license)
        {
            if (license != null && ModelState.IsValid) // licence.CustomerId is null Model.State is not valid
            {
                LicenseRepository.Repository.Insert(license);
            }
 
            return Json(new[] { license }.ToDataSourceResult(request, ModelState));
        }
 
        public JsonResult GetCustomers()
        {
            return Json(CustomerRepository.Repository.Customers, JsonRequestBehavior.AllowGet);
        }

If .OptionLabel("Select Customer...") is commented  and submit create then licence then CustomerId is null. If user change DropDownList(CustomerId) then it works fine.

Is this a bug? 

 

Nikolay Rusev
Telerik team
 answered on 09 Mar 2016
1 answer
107 views

I'm using the Telerik MVC grid with the .Pdf function. It works fine, but I'd like to format it (page title, page size, etc) but I can't find any documentation regarding it. I followed the steps this this article http://demos.telerik.com/aspnet-mvc/grid/pdf-export and I'd tried to access the documentation referred in this article: http://demos.telerik.com/aspnet-ajax/editor/examples/overview/%5C%27http:/docs.telerik.com/kendo-ui/web/grid/print-export#exporting%5C%27 but the page seems to be down or no longer active.

Can anyone give me any indication on how to achieve this?

Thanks in advance.

Federico.

Milena
Telerik team
 answered on 09 Mar 2016
3 answers
893 views

I have two grids, A and B.

 

After clicking on the save in A,

1. Before passing to the server, I like to automatically calculate values and process some values before sending back to the server.

2. if something wrong a message popup and don't send to the server

3. if everything is good, have a modal popup about sending the data to the server

4. after processing in the server, modal disappear

5. after modal disappear, retrieve the data again from the server for grid B

 

questions:

1. I think I can use ".Events(e => e.Save("onSave"))" as before saving?

2. Any event I should use for after saved?

3. anyway I can pass the data back to the server which is not inside the grid when people click on grid save.

 

thanks!

Vasil
Telerik team
 answered on 09 Mar 2016
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
Upload
ComboBox
MultiSelect
ListView
Window
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
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
Licensing
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?