I have the following model
public class CreateUserModel : DetailLayoutModel
{
public string UserName { get; set; }
public string Email { get; set; }
public List<UserSettingModel> Settings { get; set; }
}
public class UserSettingModel : BaseModel
{
public string Name { get; set; }
public int MaxPercentage { get; set; }
public int MaxValue { get; set; }
public int MinPercentage { get; set; }
public int MinValue { get; set; }
}
I have use for user settings editable kendo grid like the following:
the problem that when i press to create list the user setting list is null!
I want method to bind the kendo grid when I click save button.
I use Bind["models"] but not work
in my case I want to bind user setting list that exist in user model.
Edit 1:
the kendo grid in view ,
note: the kendo grid is filled when open. its bind the user settings to grid
My problem is :
1- when user fill values in grid and sort it or paginate the values is reset
2- when user click to submit button the the settings list not filled when received to action create , only the user name and email filled
#(Html.Kendo().Grid<UserSettingModel>(Model.Settings).Name("settings")
.Resizable(resize => resize.Columns(true))
.Pageable(a => a.ButtonCount(5).Numeric(false).Input(true))
.Scrollable(a => a.Enabled(true))
.Sortable(a => a.SortMode(GridSortMode.MultipleColumn))
.Selectable(a => a.Mode(GridSelectionMode.Single))
.Filterable(a => a.Extra(true))
.Editable(x=>x.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource.Ajax()
.PageSize(5)
.ServerOperation(false)
.Read(read => read.Action("GetSettings", "User"))
.Model(model =>
{
model.Id(o => o.Id);
model.Field(p => p.Name).Editable(false);
}))
.BindTo(Model.Settings)
.Columns(columns =>
{
columns.Bound(p => p.Name).Title(GlobalResources.Name);
columns.Bound(p => p.MinValue);
columns.Bound(p => p.MinPercentage);
columns.Bound(p => p.MaxValue);
columns.Bound(p => p.MaxPercentage);
})))
Related
I'm trying to use a Kendo grid with inline editing but my data does not change on pressing update. Other columns have no problem, but the drop down data is not updated.
My model class is:
public class Validation
{
public string ParentParameterName { get; set; }
public string ParameterName { get; set; }
public string ParameterTitle { get; set; }
[UIHint("DataTypeList")]
public string DataType { get; set; }
[UIHint("EvetHyir")]
public string Required { get; set; }
public List<Validation> Value { get; set; }
}
My grid is:
#(Html.Kendo().Grid<Validation>()
.Name("keyJsonGrid")
.Columns(columns =>
{
columns.Bound(model => model.ParentParameterName).Title("Ana parametre ünvanı");
columns.Bound(model => model.ParameterTitle).Title("Parametre ünvanı");
columns.Bound(model => model.ParameterName).Title("Parametre Adı");
//columns.Bound(foo => foo.DataType).Title("TİP").EditorTemplateName("DataType").Sortable(false);
columns.Bound(p => p.DataType).Sortable(false).Width(180).EditorTemplateName("DataTypeList");
columns.Command(command => { command.Edit().Text("Düzenle"); command.Destroy().Text("Sil"); }).Width(250);
})
.Resizable(builder => builder.Columns(true))
.ToolBar(toolbar => toolbar.Create().Text("Yeni Ekle"))
.Editable(editable => editable
.Mode(GridEditMode.InLine)
.ConfirmDelete("Silinmesine emin misiniz?")
.DisplayDeleteConfirmation("Silinmesine emin misiniz?")
)
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new int[] { 10, 25, 50, 75, 100 })
)
.Sortable(x => x.SortMode(GridSortMode.MultipleColumn))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetJsonKeyList", "Key", new { KeyId = Model }))
.PageSize(25)
)
)
My dropdown is populated from an enum:
#(Html.Kendo().DropDownList()
// The name of the widget has to be the same as the name of the property.
.Name("DataType")
// The value of the drop-down is taken from the EmployeeID property.
.DataValueField("Text")
.DataTextField("Text")
.AutoBind(true)
// The text of the items is taken from the EmployeeName property.
.ValuePrimitive(true)
// A list of all employees which is populated in the controller.
.BindTo((System.Collections.IEnumerable)ViewData["DataTypes"])
)
Dropdown data population code:
KeyJsonDTO.DataType x = KeyJsonDTO.DataType.Integer;
ViewData["DataTypes"] = EnumToSelectList(x.GetType());
static List<SelectListItem> EnumToSelectList(Type enumType)
{
return Enum.GetValues(enumType)
.Cast<int>()
.Select(i => new SelectListItem
{
Value = i.ToString(),
Text = Enum.GetName(enumType, i),
})
.ToList();
}
When I press the "Edit" button, the dropdown does not show correct data, and when I press update data, it does not update.
I doubt you are actually using the dropdown you created. "DataType" is not the name of the field. It is the name of the editor template you save in the file system. You can use controls on page but as far as i know, only if it's a javascript grid. You need to make an editor template in the appropriate folder and change the definition of the control to be an dropdownfor(m => m). Then you don't have to name it.
I have a kendo grid in which I am bounding columns from one table. But when I want to add a column from another table (JobItemModel) data in that column is empty. Please help here. Thanks
#(Html.Kendo().Grid<Modus.Presentation.Models.Jobs.JobModel>()
.Name("#jobs-grid")
.EnableCustomBinding(true)
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(x => x.Id))
.Read(read => read.Action("List", "Jobs"))
)
.Columns(columns =>
{
columns.Bound(x => x.Id).Visible(false);
columns.Bound(x => x.JobItem).Visible(false);
columns.Bound(x => x.JobNumber);
columns.Bound(x => x.Customer.Id).ClientTemplate("#= Customer.Name #");
columns.Bound(x => x.JobItem.Name);
columns.Bound(x => x.JobItem.DateCompletition);
columns.Command(command => command.Custom("View Details").Click("showDetails"));
The model:
public class JobModel
{
//public virtual int Id { get; set; }
public JobModel()
{
JobItems = new List<JobItemModel>();
}
[ModusResourceDisplayName("gp.Job.Fields.JobNumber")]
public string JobNumber { get; set; }
[ModusResourceDisplayName("gp.Job.Fields.Customer")]
public int CustomerId { get; set; }
[ModusResourceDisplayName("gp.Job.Fields.Contact")]
[UIHint("CustomerContact")]
public int ContactId { get; set; }
public List<JobItemModel>JobItems { get; set; }
public CustomerModel Customer { get; set; }
public JobItemModel JobItem { get; set; }
}
I have a Kendo UI Grid with grouping on RoleName property. I am trying to set title on the grouped property and can't seem to figure out how to do that.
The view model is below.
public class UserMembershipViewModel
{
[Display(Name = "Username")]
[UIHint("UsersDropdown")]
public string UserId { get; set; }
[Display(Name = "Group")]
[UIHint("RolesDropdown")]
public string RoleId { get; set; }
[Display(Name = "Group")]
public string RoleName { get; set; }
[HiddenInput(DisplayValue = false)]
[Display(Name = "Username")]
public string UserName { get; set; }
[HiddenInput(DisplayValue = false)]
[Display(Name = "Email")]
public string Email { get; set; }
}
The Kendo Grid is set up as follows.
Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.UserName);
columns.Bound(p => p.Email);
columns.Command(command =>
{
command.Destroy();
}).Title("Actions").Width(200);
})
.Editable(editable => editable
.Mode(GridEditMode.PopUp)
.Window(window => window
.Title("Add Group Member")
.Draggable(true)))
.ToolBar(toolbar => toolbar.Create().Text("Add Group Member"))
.Pageable()
.Sortable()
.Groupable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(user => user.UserId);
model.Field(user => user.UserId).Editable(false);
})
.Events(events => events
.Sync("sync_handler"))
.Group(group => group.Add(model => model.RoleName))
.Create(create => create.Action("MembershipCreate", "UserManagement"))
.Read(read => read.Action("MembershipRead", "UserManagement"))
.Destroy(destroy => destroy.Action("MembershipDestroy", "UserManagement"))
)
And the result is this..
The RoleName property in view model has Display attribute on it. This attribute does work for setting title on column headers (you can see the Username column header in the image), but does not work on Group headers.
So the RoleName in the image should be Group. Any ideas on how to set the group title?
add group field as hidden column with ClientGroupHeaderTemplate:
columns.Bound(p => p.RoleName).ClientGroupHeaderTemplate("#=value#").Hidden();
I have tried to follow an example to get a foreign key into a grid. I followed this example:
http://demos.telerik.com/aspnet-mvc/grid/foreignkeycolumn
I have altered it a little bit because I want to use a Popup Editor.
Here is the Grid implementation in the View.
#(Html.Kendo().Grid<Example.Web.UI.ViewModels.ExampleItem>()
.Name("ExampleGrid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.Label);
columns.Bound(p => p.Type);
columns.Bound(p => p.InputType);
columns.ForeignKey(p => p.ParentId, (System.Collections.IEnumerable)ViewData["items"], "Id", "Name").Title("Parent");
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.Id).DefaultValue(Guid.NewGuid());
model.Field(p => p.ParentId).DefaultValue(null);
})
.Create(update => update.Action("EditingPopup_Create", "Example"))
.Read(read => read.Action("EditingPopup_Read", "Example"))
.Update(update => update.Action("EditingPopup_Update", "Example"))
.Destroy(update => update.Action("EditingPopup_Destroy", "Example"))
)
)
Here is the ExampeItem Model:
public class ExampleItem
{
[ScaffoldColumn(false)]
public Guid Id { get; set; }
public string Name { get; set; }
public string Label { get; set; }
public string Type { get; set; }
[DisplayName("Input Type")]
public string InputType { get; set; }
public ExampleItem Parent { get; set; }
public Guid ParentId { get; set; }
}
In my Controller I set the foreign key items like this:
ViewData["items"] = exampleItems; // This is a List<ExapleItem>
But for some reason the Parent column is empty when the Grid is loaded.
When I click on Edit a window pops up and shows me the Guid of the parent.
That Guid should be a drop down list of items. And the Parent column should show the name of the Parent item.
The idea of this grid is that you can add items to the grid, and when you do, you can choose any of the all ready added grid items as a parent item. Then creates an hierarchy in the Grid which can be sorted later on by the Parent.
Anyone know where I have gone wrong?
Not sure but as per my experience, you forgot to add editor template for the foreign key column.
As per your code you have to add default editor templates into your project.
For default editor template detail please check this for full code/demo.
You can also create your own editor template.
For ex:-
column definition for the Product
c.ForeignKey(x => x.ProductID, (List<Product>)ViewData["products"], "ID", "ProdName").EditorTemplateName("ProductIDEditor");
Here is the editor template for Product, ProductIDEditor.cshtml
#using Kendo.Mvc.UI
#(Html.Kendo().DropDownListFor(m => m)
.AutoBind(false)
.OptionLabel("Select a value...")
.DataTextField("ProdName")
.DataValueField("ID")
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action("FilterProducts", "Home").Data("filterProducts"))
.ServerFiltering(true);
})
)
#Html.ValidationMessageFor(m => m)
Let me know if any concern.
So after trial and error I found the issue.
I changed my model to:
public class ProposalItem
{
[ScaffoldColumn(false)]
public int Id { get; set; }
public string Name { get; set; }
public string Label { get; set; }
public string Type { get; set; }
[DisplayName("Input Type")]
public string InputType { get; set; }
public ProposalItem Parent { get; set; }
[UIHint("GridForeignKey")]
public int? ParentId { get; set; }
}
So removed the Guid datatype from the Id. Also Decorated the ParentId with [UIHint("GridForeignKey")] which now gives me a DropdownList in the popup window.
It looks like there is a lack of Support for Guid's in KendoUI.
I will post another question as to why Guid's don't work.
Just add in :
.DataSource(source => source.Ajax()
.Model(model =>
{
model.Id(o => o.Id);
model.Field(o => o.Id).Editable(false);
model.Field(p => p.Id).DefaultValue(Guid.NewGuid());
model.Field(p => p.ParentId).DefaultValue(Guid.NewGuid());
**model.Field("ParentId", typeof(Guid));**
})
It has to do new Guid.
on one of my views i am using teleriks open source grid for MVC 3. i have 3 columns in the grid :
-Name
-Email
-Roles
the problem which ive got is: i want my Roles column as a dropdownlist, which is already editable when page load (so i dont want any Edit/Update buttons or stuff), so when admin change selected item in dropdownlist role of user gonna be updated.
Any idea how to make that?
View
#model IEnumerable<UserViewModel>
#(Html.Telerik().Grid(Model)
.Name("Grid").TableHtmlAttributes(new { width="800"})
.Columns(columns =>
{
//if (userIsInWhateverRole){
// columns.Template(o => Html.Action(GenerateYourLinkStuffHere));
//}
columns.Bound(o => o.Name).Width(150);
columns.Bound(o => o.Email).Width(120);
columns.Bound(o => o.Roles).Width(120);
})
.Sortable()
.Scrollable()
.Groupable()
.Filterable()
.Pageable(paging =>
paging.PageSize(5)
)
)
ViewModel
public class UserViewModel
{
public int Id { get; set; }
[Microsoft.Build.Framework.Required]
[Display(Name = "User name")]
public string Name { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
public string[] Roles { get; set; }
public string Email { get; set; }
public bool Admin { get; set; }
}
Control
public ActionResult ManageRoles()
{
var users = Membership.GetAllUsers().Cast<MembershipUser>().Select(x=> new UserViewModel{ Name = x.UserName, Email = x.Email, Roles = Roles.GetAllRoles()});
return View(users);
}
You need to use a template column and define the template as a dropdown list:
#(Html.Telerik().Grid(Model)
.Name("Grid").TableHtmlAttributes(new { width="800"})
.Columns(columns =>
{
//if (userIsInWhateverRole){
// columns.Template(o => Html.Action(GenerateYourLinkStuffHere));
//}
columns.Bound(o => o.Name).Width(150);
columns.Bound(o => o.Email).Width(120);
columns.Template (
#<text>
#Html.DropDownList("Roles", new SelectList(item.Roles))
</text>
).Width(120);
})
.Sortable()
.Scrollable()
.Groupable()
.Filterable()
.Pageable(paging => paging.PageSize(5))
)
I'm not able to test the code but it should be very close.
You want every item in the grid to be editable? Just use a template for a column that renders a textbox. See this demo: http://demos.telerik.com/aspnet-mvc/grid/templatesserverside