I have one template for the grid which I used in two places and grids have a different id's of course.
#(Html.Kendo().Grid(Model.Equipment)
.Name(string.Format("equipmentGridReview-{0}", DateTime.Now.Ticks))
.Columns(columns =>
{
columns.Bound(c => c.Quantity).Title("Qty");
columns.Bound(c => c.ItemName).Title("Item / Billing Code");
columns.Bound(c => c.ItemId).Title("Item#");
columns.Bound(c => c.Disposition).Title("Disposition");
columns.Bound(c => c.InvLoc).Title("Inv Loc");
columns.Bound(c => c.EqLoc).Title("Eq Loc");
columns.Bound(c => c.UnitPrice).Title("Unit Price").Format("{0:c}");
columns.Bound(c => c.Completed).Title("Completed");
})
.Sortable()
.Resizable(resize => resize.Columns(true))
.Events(e => e.DataBound("someModule.onDataBoundToGrid"))
.Reorderable(reorder => reorder.Columns(true))
.Selectable()
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
)
)
Here is my js module
function getEquipmentGrids() {
var grids = [];
$.each($("[id|='equipmentGridReview']"), function(idx, element) {
grids.push($(element).data("kendoGrid"));
});
return grids;
}
function onDataBoundToGrid() {
setCommonDateSource(this);
}
function setCommonDateSource(newGrid) {
$.each(getEquipmentGrids(), function(idx, grid) {
if (grid !== newGrid && grid.dataSource !== newGrid.dataSource) {
newGrid.setDataSource(grid.dataSource);
}
});
}
And when I switching between I get an error. First Array(1) I get when I first upload tab first time, second [init, init] I get when I switching between tabs.
It seems you are setting the dataSource of the second grid in the first's dataBound event. This could lead to some unintended behavior.
The good news is you don't need to do anything special for two components to share a dataSource. As you can see on the example at https://demos.telerik.com/aspnet-mvc/datasource/shared-datasource , a grid and an AutoComplete simply are passed the same dataSource, and it just works. Both will dynamically reflect any changes made to the data. The same will work for two grids, or any two widgets that have linear data.
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'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
I am using the Kendo UI (2015.3.930) Grid Control and I have a integer textbox in a grid filter row that always as decimal when I apply the filter.
Here is my code:
#(Html.Kendo().Grid((IEnumerable<UiController.Lot>)Model.Lots)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(c => c.LotNumber).Title("Lot No")
.Filterable(ftb =>ftb.ItemTemplate("NumericFilter"));
columns.Bound(c => c.BranchName).Title("Branch Name");
})
.HtmlAttributes(new { style = "height: 530px;" })
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.DataSource(dataSource => dataSource
.Server()
.Model(model => { model.Id(p => p.Id); })
)
)
My script section shows:
<script>
function NumericFilter(args) {
args.element.kendoNumericTextBox({
"spinners" : false,
"format": "n0",
"decimals": 0,
});
}
For an Integer value of 10, it shows '10.00' after the applying the filter. Is there a way of showing the value without the decimal portion.
Thanks,
I have prepared Dojo example just to show that it is possible.
I have not MVC wrappers but it looks, that it will work if you will do some small modifications to your code:
1] Change ItemTemplate in your Filterable to UI
columns.Bound(c => c.LotNumber).Title("Lot No").Filterable(ftb => ftb.UI("NumericFilter"));
2] Then you should be able to get wanted behaviour with syntax you showed in question with small (selector) modification
<script>
function NumericFilter(args) {
$(args).kendoNumericTextBox({
"spinners" : false,
"format": "n0",
"decimals": 0,
});
}
to customize this field, you need to use cell.template, please update your code as follow:
columns.Bound(c => c.LotNumber)
.Title("Lot No")
.Filterable(ftb => ftb.Cell(c => c.Template("NumericFilter")));
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