I need to add a dropdown in a Kendo Grid. I have tried to add by using EditorTemplate but something is not right in the code that's why it is not working for me.The dropdown have 3 values (Donate, Refund, Undo). Below is my kendo grid and i need to display dropdown on the first column. Please help.
#(Html.Kendo().Grid<GA.CustomerCare.Web.Synergy.Models.CustomerOrderARInfo>
(Model.CustomerOrderARInfoResult)
.Name("SearchResultsGridParent")
.Columns(columns =>
{
columns.Bound(e => e.ActionList).Width(100).EditorTemplateName("ActionDropdownEditor");
columns.Bound(e => e.TransNumber).Width(85);
columns.Bound(e => e.OriginalTransNumber).Width(85);
columns.Bound(e => e.DateEntered).Width(115);
columns.Bound(e => e.TransDate).Width(85);
columns.Bound(e => e.TransType).Width(130);
columns.Bound(e => e.Status).Width(100);
columns.Bound(e => e.Amount).Width(100);
columns.Bound(e => e.AmountApplied).Width(100);
columns.Bound(e => e.AvailableFunds).Width(85);
columns.Bound(e => e.AdjustmentReason).Width(85);
columns.Bound(e => e.CcCheckGiftCard).Width(155);
columns.Bound(e => e.PaypalTransID).Width(135);
columns.Bound(e => e.Area).Width(85);
columns.Bound(e => e.EnteredBy).Width(115);
columns.Bound(e => e.Reference).Width(155);
columns.Bound(e => e.DateCapture).Width(155);
columns.Bound(e => e.AmountCapture).Width(155);
})
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn)
)
.Resizable(resize => resize.Columns(true))
.ColumnResizeHandleWidth(10)
.Scrollable(scrolling => scrolling.Height(190))
//.ClientDetailTemplateId("template")
//.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetCustomerOrderAR", "Order", new { CustomerOrderID = Model.CustomerOrderID }))
)
)
Below is the property i am using in the Model :
[Display(Name = "ActionList")]
public string ActionList { get; set; }
Below is my ActionDropdownEditor :
#model string
#(Html.Kendo().DropDownList()
.Name("ActionList") //Important, must match the column's name
.Value(Model)
.SelectedIndex(0)
.BindTo(new string[] { "Donate", "Refund", "Undo" }))
I also tried using the kendo Grid with DropDown in the same way as you did and it worked.
Please check it with your code whether some references are missing.
column.Bound(p => p.ActionList).ClientTemplate("#= ActionList !=null ? ActionList : '' #").EditorTemplateName("_Sex").Title("ActionList");
I am giving my whole Dropdown in EditorTemplates Folder for you to check with your code:
#using Kendo.Mvc.UI
#(Html.Kendo().DropDownListFor(m => m)
.Name("ActionList").HtmlAttributes(new { #style = "font-size:12px", #class = "PaxType" })
.BindTo(new string[] { "Donate", "Refund", "Undo" }))
You can place a DropDownList into a Kendo Grid by using html in a ClientTemplate. I achieved something similar using the following...
column.Bound(p => p.WFKeyType).Title("Type").ClientTemplate("<select class='form-control'><option value='' disabled='disabled' selected='selected'>Select Key Type</option><option value='String'>String</option><option value='Integer'>Integer</option><option value='DateTime'>DateTime</option><option value='Currency'>Currency</option><option value='Bool'>Bool</option></select>");
which produces a DropDownList in the Grid Column containing 'String', 'Integer', 'DateTime', 'Currency', & 'Bool' as options. The 'form-control' class is from Bootstrap and helps the column look more clean. Your project would need to add Bootstrap 3 before the class would be accessible.
Related
I'm trying to set a min and max values for datetime picker control inside a grid. The value needs to be set dynamically, based on the value of another datepicker on the form.
I had try handling the onEdit event and trying to find the datetime picker control inside the row been edited to set those values without looking.
Whats is the proper way of restricting date ranges in Kendo Grid MVC inline editing?
This is how the grid is created:
<div>
#(Html.Kendo().Grid<CpcPrevisionUnidadesDto>()
.Name("gridListado")
.HtmlAttributes(new { #class = "kendo-grid-" })
.AutoBind(false)
.Columns(columns =>
{
columns.Bound(c => c.IdCpcPrevisionParadasUnidadesDto).Hidden();
columns.Bound(c => c.IdCpcUnidadesProceso).Hidden();
columns.Bound(c => c.CodigoUnidadProceso).Title(Html.Resource("CPC_CU_DP003_Unidad").ToString());
columns.Bound(c => c.DescripcionUnidadProceso).Title(Html.Resource("CPC_CU_DP003_Nombre").ToString());
columns.Bound(c => c.FechaParada).Title(Html.Resource("CPC_CU_DP003_FechaParada").ToString()).Format("{0:dd/MM/yyyy}").EditorTemplateName("Date"); // Need to set MAX and MIN values
columns.Bound(c => c.FechaArranque).Title(Html.Resource("CPC_CU_DP003_FechaArranque").ToString()).Format("{0:dd/MM/yyyy}").EditorTemplateName("Date"); // Need to set MAX and MIN values
columns.Bound(c => c.Observaciones).Title(Html.Resource("CPC_CU_DP003_Observaciones").ToString());
columns.Template(c => { }).Title(" ").Width(40).ClientTemplate("#=menuRuedaTemplate([uid])#").HtmlAttributes(new { style = "overflow: visible;" });
})
.DataSource(datasource => datasource
.Ajax()
.PageSize(20)
.Read(read => read.Action("BuscarPrevisionParadasPrevistasUnidades", "PrevisionParadasPrevistasUnidades").Data("setParametrosListado"))
.Create(create => create.Action("CreatePrevisionParadasPrevistasUnidades", "PrevisionParadasPrevistasUnidades").Type(HttpVerbs.Post).Data("sendAntiForgery"))
.Update(update => update.Action("UpdatePrevisionParadasPrevistasUnidades", "PrevisionParadasPrevistasUnidades").Type(HttpVerbs.Post).Data("sendAntiForgery"))
.Sort(sort => sort.Add("CodigoUnidadProceso").Ascending())
.Events(e => e.Error("screenErrorHandling"))
.Model(model => model.Id(p => p.IdCpcPrevisionParadasUnidadesDto))
)
.Sortable()
.Navigatable()
.Pageable(pager => pager.Messages(messages => messages.Display(Html.Resource("Mensaje_Grid_Datos").ToString()))
.Messages(m => m.Empty(Html.Resource("Mensaje_Grid_SinDatos").ToString())))
.Resizable(r => r.Columns(true))
.Events(e => e.DataBound("dataBoundGrid").Edit("onEdit"))
.Editable(editable => editable.Mode(GridEditMode.InCell))
.ToolBar(toolbar => toolbar.Save().SaveText(Html.Resource("MAIN_Guardar").ToString()).CancelText(Html.Resource("MAIN_Cancelar").ToString())))
</div>
This is the date editor template:
#model DateTime?
#(Html.Kendo().DatePickerFor(m => m))
You need to edit the HTML for your DatePicker and specify values for Min and Max. In this example, you will only be able to choose past values from this year.
#(Html.Kendo().DatePickerFor(m => m)
.Min("01/01/2016")
.Max(DateTime.Now)
)
If you need to set the value dynamically, you can try this, just get the value you need:
$("#Date").data("kendoDatePicker").min(new Date(2015, 0, 1))
same for .max()
Try that on your "onEdit" event, when the datepicker is created, and let me know if you need more help
So I can make this work fine in newer browsers, but in IE9 when a date is clicked on the datepicker the cell turns back as unselected, empty and not dirty.
An example of my code is
MODEL
public string name { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}", NullDisplayText = "")]
[Display(Name = "Actual Start")]
public DateTime? ActualStartDate { get; set; }
public DateTime? ActualEndDate { get; set; }
GRID
Html.Kendo().Grid<MilestoneDto>()
.Name("editMilestoneList")
.Columns(columns =>
{
columns.Bound(m => m.Name).Title("Name");
columns.Bound(m => m.Status).EditorTemplateName("_milestoneStatus");
columns.Bound(m => m.PlannedStartDateStringValue);
columns.Bound(m => m.ProjectedStartDateStringValue);
columns.Bound(m => m.ActualStartDate).EditorTemplateName("GenericDatePicker");
columns.Bound(m => m.PlannedEndDateStringValue);
columns.Bound(m => m.ProjectedEndDateStringValue);
columns.Bound(m => m.ActualEndDateStringValue).EditorTemplateName("GenericDatePicker");
columns.Bound(m => m.CommentCount).ClientTemplate("#=CommentCount#</span>#}else{#<span class=\"fa fa-plus-circle\"></span>#}#").Title("Comments").Sortable(false).IncludeInMenu(false);
})
.HtmlAttributes(new { #class = "hidden results table-responsive" })
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("DataSource", "Milestone").Data("additionalParams"))
.Update(update => update.Action("BatchEdit", "Milestone"))
.Batch(true)
.Events(e => e.Sync("SyncGrid"))
.ServerOperation(false)
.Model(m => {
m.Id(mf => mf.Id);
m.Field(f => f.Name).Editable(false);
m.Field(f => f.Status).Editable(ViewBag.IsBaselined);
m.Field(f => f.PlannedStartDateStringValue).Editable(false);
m.Field(f => f.PlannedEndDateStringValue).Editable(false);
m.Field(f => f.CommentCount).Editable(false);
m.Field(f => f.ProjectedStartDateStringValue).Editable(false);
m.Field(f => f.ProjectedEndDateStringValue).Editable(false);
m.Field(f => f.ActualStartDate).Editable(ViewBag.IsBaselined);
m.Field(f => f.ActualEndDate).Editable(ViewBag.IsBaselined);
})
)
.Editable(editable => editable.Mode(GridEditMode.InCell))
.ColumnMenu()
.Filterable()
.Sortable();
}
EDITOR TEMPLATE
#model DateTime?
#Html.TextBoxFor(model => model, new { #class="k-textbox bootStrapDatePicker form- control" })
<script type="text/javascript">
$('.bootStrapDatePicker').datepicker({ startDate: '0', format: "m/d/yyyy", autoclose: true });
</script>
You have two (better) options that will automatically set up the DateTimePicker for you:
1) In the grid columns/models, use your ActualStartDate properties. Then you can use the .Format() method on your columns to format it how you'd like.
2) I don't know what the exact syntax is, but when you're defining the Model in the Grid, I I believe there is a DataType() or similar method to set it as a date time.
It's been a while but it turns out the problems was the version of jquery was incorrect.
I have some difficulties to make a grid with an editor pop , which has inside a collection.
I found an example that 's almost like I want, but the grid
nested , has a GridEditMode.InCell , and I need to GridEditMode.PopUp .
When I try to change CellEditing PopEditing 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. "
I want the whole object is recorded when the parent object is recorded.
#(Html.Kendo().Grid<EmployeeViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Command(comm =>
{
comm.Edit();
});
columns.Bound(e => e.EmployeeID);
columns.Bound(e => e.FirstName);
columns.Bound(e => e.LastName);
columns.Bound(e => e.Title);
columns.Bound(e => e.HireDate).Format("{0:d}");
columns.Bound(e => e.Territories)
.ClientTemplate("#=territoriesTemplate(Territories)#");
})
.Editable(ed=>ed.Mode(GridEditMode.PopUp))
.Pageable()
.Events(ev=>ev.Edit("onEdit"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Model(model =>
{
model.Id(e => e.EmployeeID);
model.Field(e => e.EmployeeID).Editable(false);
model.Field(e => e.Territories).DefaultValue(new List<TerritoryViewModel>());
})
.Events(ev=>ev.Change("onDsChange"))
.Read(read => read.Action("Read", "Home"))
.Update(update => update.Action("Update", "Home").Data("serialize")))
)
This is the nested grid that need to be edited with GridEditMode.PopUp
#(Html.Kendo().Grid<TerritoryViewModel>()
.Name("TerritoryGrid")
.Sortable()
.Columns(cols =>
{
cols.Bound(b => b.TerritoryID);
cols.Bound(b => b.TerritoryDescription);
})
.Editable(ed=>ed.Mode(GridEditMode.InCell))
.AutoBind(false)
.DataSource(ds => ds.Ajax().Model(mo => {
mo.Id(m => m.TerritoryID);
mo.Field(f => f.TerritoryID).Editable(false);
}))
.ToClientTemplate()
)
Is there any way?
I assume you found the following demo and you want to change it to use popup editing for the nested Grid. It is possible to make the Grid use Popup editing, however the nested Grid will perform separate request.
If you want to achieve both Popup editing + batch updates you will have to declare your Grid via JavaScript since it provides you with way more flexibility.
Or you can use the approach covered in this code library to achieve similar to popup editing + batch updates.
Here's my grid
Class year > Course > Student
Problem
1. How can I get the key from the first grid? (classyearID from classyear grid?)
The reason I need it because I have more than 5 class years, but only have 2 courses. so basically those two coursse will exist in every class year. and since I cant get the class yearID, students are reappearing on each class year, please help
check my view below:
#(Html.Telerik().Grid<ClassYear>().HtmlAttributes(new { style = "width: 100%" })
.Name("grdClassYear")
.DataBinding(binding => binding.Ajax()
.Select("GetClassYears", "Home"))
.DataKeys(keys => keys
.Add(o => o.ClassYearID)
.RouteKey("classyearID"))
.Columns(cols =>
{
cols.Bound(c => c.ClassYearDate);
cols.Bound(c => c.Name);
})
.DetailView(course => course.ClientTemplate(
Html.Telerik().Grid<Course>()
.Name("grdCourse_<#= ClassYearID #>")
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("GetCourses", "Home"))
.DataKeys(keys => keys.Add(o => o.CourseID))
.Columns(cols =>
{
cols.Bound(c => c.CourseName);
cols.Bound(c => c.Description);
})
.DetailView(stu => stu.ClientTemplate(
Html.Telerik().Grid<Student>()
.Name("grdStudent_<#= CourseID #>")
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("GetStudentsA", "Home", new { classyearID = "<#= ClassYearID #>", courseID = "<#= CourseID #>" })))
.DataKeys(keys => keys.Add(o => o.PersonID))
.Columns(cols =>
{
cols.Bound(c => c.PersonID).ReadOnly().Hidden();
cols.Bound(c => c.MidshipmenNumber);
cols.Bound(c => c.LastName);
cols.Bound(c => c.FirstName);
})
.Sortable()
.ToHtmlString()
))
Thanks
i am not sure, whether this has been resolved yet or not. but just wants to give answer on it, so it might help somebody.
make your detail grid name as example,
.Name("grdStudent_<#= ClassYearID #>_<#= CourseID #>")
basically, each Detail View name should be unique.
I am using Telerik MVC extension version 2012.1.419.340. I had a problem with Command Column in Grid. I will use the example code on Telerik website to explain my problem.
I have view like:
#model IEnumerable<Order>
#(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(100);
columns.Bound(o => o.ShipAddress);
columns.Command(commands => commands
.Custom("viewDetails")
.Text("View Details")
.DataRouteValues(route => route.Add(o => o.OrderID).RouteKey("orderID"))
.Ajax(true)
.Action("ViewDetails", "Grid"))
.HtmlAttributes(new { style = "text-align: center" })
.Width(150);
})
.ClientEvents(events => events.OnComplete("onComplete"))
.DataBinding(dataBinding => dataBinding.Ajax().Select("_CustomCommand", "Grid"))
.Pageable()
.Sortable()
.Filterable()
)
and my Order model like
public class Order{
public int OrderID {get;set;}
public string ShipAddress {get ; set; }
public bool CanEdit {get; set;}
}
I would like my Command Column to use different Action depending on CanEdit value. For example, if CanEdit is false, using action
columns.Command(commands => commands
.Custom("viewDetails")
.Text("View Details")
.DataRouteValues(route => route.Add(o => o.OrderID).RouteKey("orderID"))
.Ajax(true)
.Action("ViewDetails", "Grid"))
.HtmlAttributes(new { style = "text-align: center" })
if CanEdit is true, using action
columns.Command(commands => commands
.Custom("editDetails")
.Text("Edit Details")
.DataRouteValues(route => route.Add(o => o.OrderID).RouteKey("orderID"))
.Ajax(true)
.Action("EditDetails", "Grid"))
.HtmlAttributes(new { style = "text-align: center" })
Can you give me some idea how to implement it?
Thanks
Finally I solved this issue by using Template Column in the Grid. I found there is no way to change Text for command column on demand. Thanks