Kendo MVC batch editing change row color or focus - kendo-ui

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

Related

kendo datagrid update event is not fired when grouped on a column

I have a kendo data grid grouped default by a column and I want to edit the grid inline. I don't want the user to group by any other column. While the default grouping works fine, the update event is not fired and the control doesn't go the controller's inline update method. Can you please check where I'm going wrong. Below is the code:
#(Html.Kendo().Grid(Model)
.Name("grdTimesheets")
.Columns(columns =>
{
columns.Bound(p => p.EmployeeId).Hidden(true);
columns.Bound(p => p.FirstName);
columns.Bound(p => p.Monday.Hour).Title("Monday")
.EditorTemplateName("TimesheetMonday");
columns.Command(command =>
{
command.Edit();
command.Destroy();
command.Custom("Add").Text(" ").Click("AddNewTimesheet");
});
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Groupable(false)
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.EmployeeId);
model.Field(p => p.FirstName).Editable(false);
})
.PageSize(20)
.Update(update => update.Action("EditingInline_Update", "Timesheet"))
.Destroy(destroy => destroy.Action("EditingInline_Destroy", "Timesheet"))
.Group(d=>d.Add(f=>f.FirstName))
)
If I comment out the last line ".Group(d=>d.Add(f=>f.FirstName))", everything works fine but the default grouping goes off.
I know that its a bit late for an answer but I will just leave this here in case that anybody else is having the same problem. Once you group by any column the grid will not fire ".Update(update => update.Action("EditingInline_Update", "Timesheet"))". In order to fix this you would need to add OnEditEvent for the grid and in the javascript function to attach an event to the textbox/dropdown or whatever control you have there. Sample below:
.Events(events => events.Edit("grid_edit")) this is in the view
javascript:
function grid_edit(e) {
var grid = $('#grid').data('kendoGrid');
var cell = e.container;
var area = cell.find("textarea")
area.on("blur", function() {
// update ur entries here
var areaVal = cell.find("textarea").val(); // this is the new value
// call some ajax to update the value and in the success call grid.dataSource.sync(); to refresh the grid
});}
Also you would need to remove your .Update() for the DataSource because its no longer needed.

Dynamically limit date range in Kendo Grid MVC date column

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

Kendo Grid with client CRUD, cancel remove row, can not set the ID properly

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)
)
)

Kendo grid in edit mode doesn't fire push event

My grid is build like this:
#(Html.Kendo().Grid<MyProject.Models.DataObjects.MyObject>()
.Name("my-object-grid")
.Columns(columns =>
{
columns.Bound(p => p.ID).Hidden();
columns.Bound(p => p.Name).Width(300);
columns.Command(command =>
{
command.Edit().Text("Modify")
.UpdateText("Save")
.CancelText("Cancel")
.HtmlAttributes(new { style = "width:90px;height:30px;font-size:12px;" });
command.Destroy().Text("Delete").HtmlAttributes(new { style = "width:90px;height:30px;font-size:12px;" });
}).Width(220);
})
.ToolBar(toolbar => toolbar.Create().Text("Add").HtmlAttributes(new { style = "width:120px;height:30px;float:left;" }))
.Editable(editable => editable.Mode(GridEditMode.PopUp)
.Window(win => win.Title("MyObject")).TemplateName("MyObject"))
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model =>
{
model.Id(p => p.ID);
})
.Create(update => update.Action("MyObject_Create", "MyObject"))
.Read(read => read.Action("MyObject_Read", "MyObject"))
.Update(update => update.Action("MyObject_Update", "MyObject"))
.Destroy(update => update.Action("MyObject_Delete", "MyObject"))
.Events(evt => evt.Push("myObjectGridDataSource_push").Error("myObjectGridDataSource_error"))
)
)
And the foolwingo javacript handlers are defined after:
<script type="text/javascript">
function myObjectGridDataSource_push(e) {
alert(e.type);
}
function myObjectGridDataSource_error(e) {
alert(e.status);
}
</script>
The javascript generated by the helper seems to be ok, but the event handlers are never fired when I add/edit/remove some item of the grid. But the requests to the controller are working fine.
Could be this related to the edit mode of the grid (using popup)?
I can't find what I am doing wrong...
Push is invoked during dataSource transport initialization which sets up push notifications. The data source will call this function only once and provide callbacks which will handle push notifications (data pushed from the server).
Push event Detailed information
If you can tell what exactly you are trying to achieve then I can be of a bit more help. Also if you want to catch the event before the record id being udpated or inserted or deleted then push won't do it. You will need to implement the sync event of the grid.

Kendo grid with nested collection , complex object

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.

Resources