Entity Model for Country (All models are in a separate project)
[ScaffoldColumn(false)]public int CountryId { get; set; }public string ShortName { get; set; }public string LongName { get; set; }public string IsoCode2 { get; set; }public string IsoCode3 { get; set; }public string IsoCodeHash { get; set; }public string CallingCodeOne { get; set; }public string CallingCodeTwo { get; set; }public string CurrencyName { get; set; }public string CurrencySymbol { get; set; }public List<State> States { get; set; }Entity Model for State
[ScaffoldColumn(false)]public int StateId { get; set; }public string Name { get; set; }public bool IsCapital { get; set; }[ScaffoldColumn(false)]public int CountryId { get; set; }public Country Country { get; set; }
States Controller deriving from ODataController (It's a separate project)
private DataAccess.Helper.DatabaseContext _dbContext;public StatesController(){ DataAccess.MyApp.StartUp.Initialize(); const string dataSource = "My-PC\\SQLEXPRESS"; const string initialCatalog = "BS"; var connString = SqlConnection.CreateConnectionString("", dataSource, initialCatalog); _dbContext = new DatabaseContext(connString);}// GET odata/Countries[EnableQuery]public System.Linq.IQueryable<State> GetStates(){ return _dbContext.States;}public IHttpActionResult Put([FromODataUri] int key, State entity){ if (!ModelState.IsValid) return BadRequest(ModelState); if (key != entity.StateId) return BadRequest(); _dbContext.States.Attach(entity); _dbContext.Entry(entity).State = EntityState.Modified; try { _dbContext.SaveChanges(); } catch (Exception) { if (!EntityExists(key)) { return NotFound(); } else { throw; } } return Updated(entity);}private bool EntityExists(int key){ return _dbContext.States.Count(e => e.StateId == key) > 0;}public IHttpActionResult Post(State entity){ if (!ModelState.IsValid) return BadRequest(ModelState); _dbContext.States.Add(entity); _dbContext.SaveChanges(); return Created(entity);}
View (It's in a separate project)
@(Html.Kendo().Grid<SC.BS.EntityModel.State>() .Name("EntityStates") .Columns(col => { col.Bound(e => e.StateId); col.Bound(e => e.Name).Title("State").Width("200"); col.Bound(e => e.IsCapital).Title("Capital").Filterable(false).Width(100).ClientTemplate("#= IsCapital ? 'Yes':'No' #").HtmlAttributes(new {style="align=center"}); col.Bound(e => e.CountryId); col.Bound(e => e.Country).Title("Country").ClientTemplate("#: Country.ShortName #").EditorTemplateName("CountriesLookUp").Filterable(false); col.Command(cmd => { cmd.Edit(); cmd.Destroy(); }).Width(170); }) .Scrollable() .ToolBar(tb => tb.Create().Text("New State")) .DataSource(ds => ds .Custom() .Schema(sch => { sch.Model(m => { m.Id("StateId"); m.Field(e => e.StateId).Editable(false); m.Field(e => e.CountryId).DefaultValue(1); //m.Field(e => e.Country).DefaultValue(new SC.BS.EntityModel.Country()); //m.Field("CreatedOn", typeof(DateTime)); }); }) .Type("odata-v4") .Transport(tr => { tr.Read(r => r.Url("http://localhost:28016/oData/States").Data("function() {return {'$expand' : 'Country'} }")); tr.Create(c => c.Url("http://localhost:28016/oData/States")); tr.Update(new { url = new Kendo.Mvc.ClientHandlerDescriptor { HandlerName = @"function(data) { return 'http://localhost:28016/oData/States(' + data.StateId + ')'; }" } }); tr.Destroy(new { url = new Kendo.Mvc.ClientHandlerDescriptor { HandlerName = @"function(data) { return 'http://localhost:28016/oData/States(' + data.StateId + ')'; }" } }); }) .PageSize(20) .ServerPaging(true) .ServerSorting(true) .ServerFiltering(true) ) .Pageable() .Sortable() .Filterable(ftb => ftb.Mode(GridFilterMode.Row)) .Editable(e => e.Mode(GridEditMode.InLine)))
CountriesLookUp EditorTemplate
@model SC.BS.EntityModel.Country@(Html.Kendo().DropDownList().Name("Countries").DataSource(ds => ds .Custom() .Schema(sch => { sch.Model(m => { m.Id("CountryId"); }); }) .Type("odata-v4") .Transport(tr => { tr.Read(r => r.Url("http://localhost:28016/oData/Countries")); })).DataValueField("Country").DataTextField("ShortName"))
Displaying data works fine, but I'am having trouble updating the State.
message=entity : The property 'Countries' does not exist on type 'SC.BS.EntityModel.State'. Make sure to only use property names that are defined by the type.This is the JSON that is sent on update command.
{"StateId":"1","Name":"Delhi","IsCapital":true,"CountryId":"2","Country":{"CountryId":2,"ShortName":"United States","LongName":"United States of America","IsoCode2":"US","IsoCode3":"USA","IsoCodeHash":"840","CallingCodeOne":"1","CallingCodeTwo":"","CurrencyName":"USD","CurrencySymbol":"$"},"Countries":"United States"}
I want to persist what child detail grid is open on return to the page. I tried using the localstorage example
var options = kendo.stringify(grid.getOptions()) localStorage.setItem("kendo-grid-options", options);but this does not seem to keep the open expanded row details.
Is there an event that fires when oi expand a row, then maybe I could use that to record the row number and expand using js when page is loaded, thanks
I have very large data sets I want to display in a grid, and I'd like to use the auto filtering on the column header. But with my large data sets, users will typically want to specify a few filters before getting their data, otherwise the retrieval of the records from the database takes a very long time.
It seems that by default, each filter in the grid is applied immediately. I'd like to allow the user to select multiple filters, and then push a button to trigger the refresh.
Is there a good way to skip the automatic refresh that comes with setting a filter in the grid header?
Hi
I have installed a trial version to have a play around with the Scheduler control.
I have put together a basic ​page, but have a problem when attempting to edit an event. After double clicking on the event, the event dialog opens. Then, whenever I hit Cancel or the close (X) button, I get the following error:
Unhandled exception at line 10, column 30735 in kendo.all.min.js
Javascript runtime error: unable to get property 'uid' of undefined or null reference.
The Save button works fine.
I am using Kendo.Mvc.dll 2015.2.805.545, and Visual Studio 2013.
Any ideas on why this is failing?
Cheers, Jarrod
Hi
Please may we have a similar "Navigator" feature as in the Stock chart, for the Scatter chart.
At least where the X axis is time.
This would be of great benefit.
Alternatively how may we customise using two sliders a similar feature.
Kind Regards
David
Hello,
I have been trying to figure out how to set value of my multiSelect after server filtering and adding some conditions so that some elements cannot be deleted. The multiselect works fine *as long* as the user uses the mouse to select elements to add. Once the user decides to filter by using the keyboard the multiselect does not render the added item correctly even though the values i set to them are correct.Here is my code:
Edit.cshtml:
@Html.Kendo().MultiSelect().Name("msGroupMembers").DataTextField("FullName").DataValueField("Id").Value(new[] { new { FullName = Model.SelectedTO.Select(x => x.Text), Id = Model.SelectedTO.Select(x => x.Value) } }).Filter(FilterType.Contains).Events(e => e.Change("onChangeEdit").Close("onCloseEdit").Select("onSelect")).DataSource(source => source
.Custom()
.Transport(transport => transport
.Read(read =>
{
read.Action("GetGroupMembers", "ScheduleRequest")
.Data("testOfficerFiltering");
}))
.ServerFiltering(true)).HtmlAttributes(new { required = "required" })
Controller:
public ActionResult SetGroupMembers(List<int> items, string teamLead)
{
Business.Entities.RTSSUser user = userService.GetRTSSUser(User.Identity.Name);
// check to see if we have a lead.
int lead;
bool result = int.TryParse(teamLead, out lead);
if (!result)
{
lead = -1;
}
try
{
int findLead = items.FindIndex(s => s == lead);
int findOwner = items.FindIndex(s => s == user.Person.Id);
//if our owner is also the lead, place in first spot
if (findLead == findOwner && findOwner == -1)
{
items.Insert(0, user.Person.Id);
}
else if (findLead == -1)
{
items.Insert(1, lead);
}
else if (findOwner == -1)
{
items.Insert(0, user.Person.Id);
}
}
catch (Exception e)
{
// handle an empty list passed.
List<int> msUsers = new List<int>();
msUsers.Insert(0, user.Person.Id);
return Json(msUsers, JsonRequestBehavior.AllowGet);
}
return Json(items, JsonRequestBehavior.AllowGet);
}​
Javascript:
function onChangeEdit(e) {
var lead = $("#cbTeamLeadName").data("kendoComboBox").value();
var msValue = this.value();
var arrayLength = msValue.length;
var newArrayValue = new Array();
//store values into array
for (var i = 0; i < arrayLength; i++) {
newArrayValue.push(msValue[i]);
console.log(msValue[i]);
}
//get owner
$.ajax({
type: 'GET',
url: SetGroupMembersUrl,
data: {
"items": newArrayValue,
"teamLead": lead
},
contentType: 'application/json',
async: true,
cache: false,
dataType: 'json',
traditional: true,
success: function (data) {
populateMs(data);
},
error: function () {
console.log("Could not get AgencyName");
}
});
}
function populateMs(e) {
var multiSelect = $("#msGroupMembers").data("kendoMultiSelect");
multiSelect.dataSource.filter({});
multiSelect.value([])
multiSelect.refresh();
multiSelect.value(e);
alert("Dat: " + e);
}
I have found this similar thread: http://stackoverflow.com/questions/22010796/kendo-multiselect-value-setting-bug and was wondering if it is a bug or if i am doing something wrong. Thanks in advance!
I have been looking at the datepicker mask example at
http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/datepicker/how-to/masked-date-picker-grid
Is this solution valid for MVC wrappers also?
I have included the code but still no mask.
Thanks