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
Related
I have a grid bind to SignalR hub on what's down
#(Html.Kendo().Grid<MyDownloader.Core.ViewModel.DownloaderViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.LocalFile);
columns.Bound(c => c.FileSize);
columns.Bound(c => c.StatusMessage);
columns.Bound(c => c.Progress);
columns.Bound(c => c.Left);
columns.Bound(c => c.Rate);
columns.Bound(c => c.CreatedDateTime);
columns.Bound(c => c.State);
columns.Bound(c => c.ResourceLocation);
columns.Command(c => c.Destroy());
})
.HtmlAttributes(new { style = "height: 550px;margin-bottom:20px;" })
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.SignalR()
.AutoSync(true)
.Events(events => events.Push("onPush"))
.Sort(s => s.Add("FileSize").Descending())
.Transport(tr => tr
.Promise("hubStart")
.Hub("hub")
.Client(c => c
.Read("read")
.Create("create")
.Update("update")
.Destroy("destroy"))
.Server(s => s
.Read("read")
.Create("create")
.Update("update")
.Destroy("destroy"))).Schema(schema => schema
.Model(model =>
{
model.Id("FileSize");
}))
))
I want to update all client when an object added to database (Downloader Table)
I call read() client method out side the hub like this
var context = GlobalHost.ConnectionManager.GetHubContext<Hubs.DownloadrHub>();
context.Clients.All.read();
but read() method not raised and grid not refresh and Data not update
How can update all client grid out of the Hub?
Usually you don't call the read method on the client. You call the create, update or delete method. Depending on the action performed. The grid handles it automagically.
E.g. Clients.All.update(new { Data = whateveryourdatais );
Have a look at the telerik examples.
I have a Kendo Grid in a form with editable information and I would like the information save with one submit. It has CRUD functions and it is inline editable. All the save and edit works fine. However, whenever I add a new row->update->edit->cancel, the row got removed. There is a lot of articles say that it is the ID issue of each record. I add the
e.model.set('id', newId); e.model.set('CommentsID', newId);
in the SaveEvent, but it doesnt get changed. I looked one of the post in stack, one of them has the same issue:
Kendo UI MVC inline client-side grid - clicking cancel removes row. Not the model ID issue
But there are two issues for me(maybe I am wrong): one is the Guid that it generates is converted to string while my CommentsID is an int; Second, which the one that I mentioned above, I can not change the value of a model using e.model.set().
Since the only information I care about is the comment, I am wondering if there is any way that I can put a dummy ID to make it work so that the Cancel button won't remove the row when it is editing.
I also checked several links, but still didn't see any good solution.
Here is my code for the view:
#(Html.Kendo().Grid((IEnumerable<EE.BusinessLayer.ProviderLogic.POCO.CommentPOCO>)Model.Comments)
.Name("Comments")
.Columns(columns =>
{
columns.Bound(c => c.CommentsID).Hidden();
columns.Bound(c => c.ModifiedDate).Title("").Width(300).ClientTemplate("#=kendo.format(\"{0:MM/dd/yyyy hh:mm tt}\",kendo.parseDate(ModifiedDate))#" + "<br> #=UserName#");
columns.Bound(c => c.Comment).Title("").EditorTemplateName("TextAreaTemplate").ClientTemplate("<div style='max-width:465px;'>#=Comment#</div>").HtmlAttributes(new { style="max-width:470px;"});
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.Events(e => e.Edit("editEvent").Save("saveEvent"))
.ToolBar(toolbar => toolbar.Create().Text("Add Comment"))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(ds => ds
.Ajax()
.Model(m => {
m.Id(p => p.CommentsID);
m.Field(p => p.CommentsID);
m.Field(p => p.ProviderID).Editable(false);
m.Field(p => p.ModifiedDate).Editable(false);
m.Field(p => p.ModifiedUserID).Editable(false);
m.Field(p => p.Comment).Editable(true);
})
.Create(update => update.Action("GridNullFunction", "Provider"))
.Update(update => update.Action("GridNullFunction", "Provider"))
.Destroy(update => update.Action("GridNullFunction", "Provider"))
.ServerOperation(true)
)
)
I am a new babie for Kendo UI for MVC, I am trying to customise row color when doing batch editing for a grid, I looked in the internet but couldn't find any info. After editing a cell for batch editing grid by default Kendo add a small red spot at the top left hand side of the cell , what I want to achieve after editing any cell the whole row for that record change change it color. I would like to change the row to green for example to give the user more visibility what row have been edited before click save. I would really app if someone could help me.
code
#(Html.Kendo().Grid<MvcKendo.Models.Availablity>().Name("grid")
.Columns( columns => {
columns.Bound(c => c.Id);
columns.Bound(c => c.TimeFrom);
columns.Bound(c => c.TimeTo);
})
.DataSource(datasource => datasource.Ajax().PageSize(5)
.Read("GetDataAvailablity","Home"))
.ClientDetailTemplateId("template")
)
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().TabStrip()
.Name("tabStrip_#=Id#")
.SelectedIndex(0)
.Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
.Items(items =>
{
items.Add().Text("TimeSheet Details").Content(#<text>#TimeSheetDetails()</text>);
})
.ToClientTemplate()
)
#helper TimeSheetDetails()
{
#(Html.Kendo().Grid<MvcKendo.Models.TimeSheet>()
.Name("grid_#=Id#")
.Events(e => {
e.DataBound("onDataBound");
e.Change("ChangeEvent");
})
.Columns(columns =>
{
columns.Bound(t => t.Id);
columns.Bound(t => t.WardName);
})
.Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
.Editable(editable => editable.Mode(GridEditMode.InCell))
.ToolBar(tb=>tb.Save())
.DataSource(dataSource => dataSource
.Ajax().Batch(true)
.PageSize(5)
.Model(model=>model.Id(x=>x.Id))
.Read(read => read.Action("GetDataTimeSheet", "Home", new { Id = "#=Id#" }))
.Update(update => update.Action("Editing_Update", "Home"))
.Events(events => events.Error("error_handler"))
)
.Pageable().Sortable().ToClientTemplate()
)
![enter image description here][2]}
You can make use of the save event in Kendo grid to achieve this
C#
.Events(events => events.Save("onSave")
Javascript
function(e) {
$(e.container).closest("tr").css("background-color","lightgreen");
}
Here's the fiddle for the sample in JS
I've got a hierarchical Kendo UI Grid (MVC Server Helpers) where one of the columns is a FK lookup that is backed with an Editor Template that does an AJAX lookup for the values. All of that works perfectly. What's not working is the column is showing the ID (Data Value Field from the drop down) and not the text (Data Text Field from the drop down).
Here's the Grid
#(Html.Kendo().Grid<ReceivingLogItemResponse>()
.Name("grid_#=GID#")
.Editable(e => e.Mode(GridEditMode.InCell))
.Sortable()
.Columns( c=>
{
c.Bound(i => i.GID).Hidden();
c.Bound(i => i.SerialNumber);
c.Bound(i => i.PartNumber);
c.Bound(i => i.Description);
c.Bound(i => i.Quantity);
c.Bound(i => i.ItemLotNumber).Title("Lot");
c.Bound(i => i.StatusId).Title("Status");
c.Bound(i => i.CategoryId).EditorTemplateName("ClientCategory");
c.Bound(i => i.LocationCode).Title("Location");
c.Bound(i => i.Comments);
c.Command(e => e.Custom("Add").Click("doItemAdd"));
})
.ToolBar(t => t.Save())
.Selectable(s => s.Type(GridSelectionType.Row))
.DataSource(dataSource => dataSource
.WebApi()
.Model(m =>
{
m.Id(i => i.GID);
m.Field(i => i.GID).Editable(false);
})
.Batch(true)
.ServerOperation(false)
.Read(read => read.Url(apiWrapper.receivingLogItemUrl() + "&receivingLogId=#=GID#").Type(HttpVerbs.Get))
.Update(u => u.Url(apiWrapper.receivingLogItemUpdateUrl()).Type(HttpVerbs.Post))
)
.Events(e => e.DataBound("itemDataBound"))
.ToClientTemplate()
)
And here's the EditorTemplate (ClientCategory)
#(Html.Kendo().DropDownList()
.Name("CategoryId")
.DataTextField("Code")
.DataValueField("CID")
.AutoBind(true)
.DataSource(ds => ds.Read(a => a.Url(apiWrapper.clientCategoryUrl()).Data("getClientCategoryID()"))))
The column displays the CID field until you enter it for editing, when the drop-down shows up it's populated with the correct values. When you go to another field it goes back to the CID.
What am I missing?
I wrote the code to display the information in Kendo UI grid.
It's using the inline grid mode to update and insert the record.
Here the code:
Timesheet.cshtml
#model HalsionTimesheetWebApp.Models.TimesheetIndexData
#(Html.Kendo().Grid(Model.TimesheetPrinting)
.Name("InlineGrid")
.Columns(columns =>
{
columns.Bound(trans => trans.TimesheetId).Title("ID").Hidden(true)
.EditorTemplateName("TimesheetIdEditor");
columns.Bound(trans => trans.StartDate).Title("Date")
.Format("{0:dd MMM yyyy}").EditorTemplateName("DateEditor").Width(100));
columns.Bound(trans => trans.StartTime).Title("Start Time")
.Format("{0:hh:mm tt}").EditorTemplateName("TimeEditor").Width(85);
columns.Bound(trans => trans.FinishTime).Title("Finish Time")
.Format("{0:hh:mm tt}").EditorTemplateName("TimeEditor").Width(85); columns.Bound(trans => trans.TimeTaken).Title("Taken")
.Format("{0:n2}")
.EditorTemplateName("TimeTakenEditor").Width(70);
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(250).Title("Action");
})
.ToolBar(toolbar => toolbar.Create().Text("New entry"))
.Editable(editable => editable.Mode(GridEditMode.InLine)
.Sortable()
.Pageable(pager => pager
.PageSizes(new int[] { 5, 10, 20, 50, 100 }).Info(true).Messages(messages => messages.Empty("No entry")
.Display("Showing entries from {0} to {1}. Total entries: {2}").ItemsPerPage("entries per page"))
)// Enable paging
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(true)
.Events(events => events.Error("datasource_error_handler")
.Model(model =>
{
model.Id(p => p.TimesheetId);
})
.Read(read => read.Action("Read", "Timesheet))
.Create(update => update.Action("Create", "Timesheet"))
.Update(update => update.Action("Update", "Timesheet"))
.Destroy(update => update.Action("Destroy", "Timesheet"))
))
EditorTemplates/DateEditor.cshtml
#model DateTime
#(Html.Kendo().DatePickerFor(m => m)
.Format("{0:yyyy-MM-dd}").Max(DateTime.Now.Date.AddDays(1).AddTicks(-1)))
EditorTemplates/TimeEditor.cshtml
#model DateTime?
#(Html.Kendo().TimePickerFor(m => m))
EditorTemplates/TimeTakenEditor.cshtml
#model int
#(Html.Kendo().NumericTextBoxFor(m => m)).Min(0).Max(int.MaxValue)
.Format("# min"))
In this code, each column has its own editor template.
What I need here is to combine some fields into a single cell in inline editing mode.
For example :
Start date and time into a single cell,finish time and time taken into another single cell.
EditorTemplates/StartDateTimeEditor.cshtml
#model DateTime?
#(Html.Kendo().DatePickerFor(m => m) // It's for Start Date
.Format("{0:yyyy-MM-dd}").Max(DateTime.Now.Date.AddDays(1).AddTicks(-1)))
#(Html.Kendo().TimePickerFor(m => m)) // It's for Start Time
EditorTemplates/FinishTimeAndTimeTakenEditor.cshtml
#model object
#(Html.Kendo().TimePickerFor(m => m)) // It's for Finish Time
#(Html.Kendo().NumericTextBoxFor(m => m)).Min(0).Max(int.MaxValue)
.Format("# min")) // It's for Time Taken
Is it possible in Kendo UI Grid ?
I don't find any documentation to support this features in Telerik Kendo UI.
Any help is appreciated.
Thank you.
You are so close! Just put two or more of your fields in the same editor template. So maybe start and finish date in the same editor, then that column uses that editor template but only one cell, if you seen what I mean? Imagine the below in a single editor template:
#model DateTime?
#model object
#(Html.Kendo().DatePickerFor(m => m) // It's for Start Date
.Format("{0:yyyy-MM-dd}").Max(DateTime.Now.Date.AddDays(1).AddTicks(-1)))
#(Html.Kendo().TimePickerFor(m => m)) // It's for Start Time
EditorTemplates/FinishTimeAndTimeTakenEditor.cshtml
#(Html.Kendo().TimePickerFor(m => m)) // It's for Finish Time
#(Html.Kendo().NumericTextBoxFor(m => m)).Min(0).Max(int.MaxValue)
.Format("# min")) // It's for Time Taken