I'm trying to add an kendo autocomplete column to my kendo grid and its not working. I tried using the telerik example with a datasource function instead of view bag as there will be lots of data to pull from.
i used an kendo autocomplete widget outside the grid and it worked. all i need is to get it to work on the grid column.
i tried the editor templates and its not working. i cant even see the column "Vendor" appearing on the grid.Here's my code.
#(Html.Kendo().Grid<Budget.ProductFieldsTRC>().Name("GridProductsTrc").Columns(columns =>{columns.Bound(p => p.ValidationErrors).Title("Validation Errors").Width(300);columns.Bound(p => p.VendorNo).Title("Vendor No").Width(250);columns.Bound(p => p.Vendor).EditorTemplateName("VendorEditor");columns.Bound(p => p.VendorName).Title("Vendor Name").Width(250);columns.Bound(p => p.Project).Title("Project").Width(250);columns.Bound(p => p.ZZZValue).Title("Prefix").Width(250);columns.Bound(p => p.Manf).Title("Manf").Width(250);columns.Bound(p => p.Type).Title("Type").Width(250);columns.Bound(p => p.Component).Title("Component").Width(250);columns.Bound(p => p.Description).Title("Description").Width(250); columns.Command(command =>
{
command.Edit();
}
)
.Width(200);
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Navigatable()
.Pageable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple)
.Type(GridSelectionType.Cell))
.HtmlAttributes(new { style = "height:400px" })
.Resizable(conf => conf.Columns(true))
.Scrollable()
.Pageable(pager => pager
.PageSizes(true)
.Messages(messages => messages.ItemsPerPage("items are currently displayed"))
)
.Reorderable(reorder => reorder.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Update(update => update.Action("UpdateGridTrc", "Customer"))
.PageSize(20)
.Model(model =>
{
model.Id(x => x.RowID);
model.Field(fld => fld.VendorNo).Editable(true);
model.Field(fld => fld.Vendor).Editable(true);
model.Field(fld => fld.VendorName).Editable(true);
model.Field(fld => fld.Project).Editable(true);
model.Field(fld => fld.ZZZValue).Editable(true);
model.Field(fld => fld.Manf).Editable(true);
model.Field(fld => fld.Type).Editable(true);
model.Field(fld => fld.Component).Editable(true);
model.Field(fld => fld.Description).Editable(true);
model.Field(fld => fld.ValidationErrors).Editable(false);
})
.Read(read => read.Action("ViewProductGridTRC", "Customer"))
)
)
MY EDITOR TEMPLATE -in the views/ shared/ editor template folder - called VENDOREDITOR
#model string#(Html.Kendo().AutoComplete().Name("Vendor").DataTextField("VendorName").Placeholder("Type a vendor name").Template("#= VendorNo # | For: #= VendorName #").ValuePrimitive(true).Filter("contains").MinLength(1).DataSource(source =>{source.Read(read =>{read.Action("GetVendorList", "Customer").Data("onAdditionalData");}).ServerFiltering(true);}))
my filtering method for the autocomplete onAdditionalData method
function onAdditionalData() {
return {
text: $("#Vendor").val()
};
}
MY CONTROLLER ACTION METHOD FOR THE AUTOCOMPLETE DATASOURCE
public JsonResult GetVendorList(string text)
{
var result = GetVendors();
if (!string.IsNullOrEmpty(text))
{
result = result.Where(p => p.VendorName.Contains(text)).ToList();
}
return Json(result, JsonRequestBehavior.AllowGet);
}
AND
private static IEnumerable<Vendor> GetVendors()
{var result = Enumerable.Range(0, 10).Select(i => new Vendor{VendorNo = "" + i,VendorName = "Vendor " + i}); return result;
}
Related
I'm not too familiar with Kendo and have watched some tutorials but even following exactly I do not get the same result. I made a page using cached data and pass it as a datasource to the grid in different ways.
In this code, the read method is not being called at all. I have no idea why.
#(Html.Kendo().Grid<TestCategory>().Name("TCategory1").Columns(c =>
{
c.Bound(p => p.Name);
c.Bound(p => p.Id);
})
.DataSource(d => d.Ajax().Read(r => r.Action("Read", "Category").Type(HttpVerbs.Get))
.PageSize(3))
.Pageable()
.Sortable()
.Filterable()
)
In the second grid, I am able to get the data to display but not able to edit
#(Html.Kendo().Grid(Model).Name("TCategory").Columns(c =>
{
c.Bound(p => p.Name);
c.Bound(p => p.Id);
c.Command(com => { com.Edit(); com.Destroy(); });
})
.DataSource(d => d.Ajax().ServerOperation(false).PageSize(3)
.Update(u => u.Action("Edit", "Category"))
.Create(c => c.Action("Create", "Category"))
.Destroy(c => c.Action("Delete", "Category"))
.Model(m => { m.Id(p => p.Id); })
)
.Pageable().Editable(e => e.Mode(GridEditMode.InCell)).Sortable().Filterable().ToolBar(t => t.Create()) )
Read method:
[HttpPost]
public JsonResult Read([DataSourceRequest]DataSourceRequest request)
{
IQueryable<TestCategory> cat = context.Collection();
return Json(cat.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
I have a simple question I cannot seem to find the answer to. I would like the grid to default to show all results on load. If possible even take out the paging at the bottom but I cannot seem to find it anywhere.
This is my grid:
#(Html.Kendo().Grid<Website.Models.LinesForPayType.LinesForPayTypeGridModel>()
.Name("gridAssignLines")
.ToolBar(toolbar =>
{
toolbar.Create().HtmlAttributes(new { #id = "CreatePaymentTypeLine", #style = "display:inline-block;" });
toolbar.Save().SaveText("Create Invoice").HtmlAttributes(new { id = "create-invoice", href = "#" }); ;
})
.Columns(columns =>
{
columns.Select().Width(30);
columns.Bound(c => c.Description);
columns.Bound(c => c.LineNo);
columns.Bound(c => c.Quantity);
columns.Bound(c => c.UnitPrice)
.ClientTemplate(Model.HomeCurrencySymbol + " #=kendo.toString(UnitPrice ? UnitPrice : 0,'n2')#");
columns.Bound(c => c.Total)
.ClientTemplate(Model.HomeCurrencySymbol + " #=kendo.toString(Total ? Total : 0,'n2')#");
})
.Events(e => e.DataBound("AddStudentController.onCheckClick"))
.Pageable(page => page
.Refresh(true)
.PageSizes("All")
)
.Editable(edit => edit.Mode(GridEditMode.InCell))
.Scrollable()
.Events(events => events.Save("AddStudentController.onInvoiceGridSave"))
.Reorderable(reorder => reorder.Columns(true))
.NoRecords("No data")
.Filterable(f => f.Operators(o => o.ForString(fs => fs.Clear().Contains("Contains").StartsWith("Start With").EndsWith("End with").IsEqualTo("Is equal to").IsNotEqualTo("Is not equal to"))))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Sort(s =>
{
s.Add(a => a.LineNo).Ascending();
})
.Model(model =>
{
model.Id(i => i.ID);
})
.Read(read => read.Action("ReadPaymentTypeLines", "Payment").Data("AddStudentController.getPaymentTypeID"))
.Create(create => create.Action("CreatePaymentTypeLines", "Payment"))
.Update(update => update.Action("CreatePaymentTypeLines", "Payment"))
)
)
Set the datasource's PageSize to int.MaxValue (e.g. https://docs.telerik.com/aspnet-mvc/api/Kendo.Mvc.UI.Fluent/GridBuilder#datasourcesystemstring) and if you don't want to see the paging stuff, set Pageable to false.
How to filter second Dropdown based on first dropdown value inside the Kendogrid
enter code here
#(Html.Kendo().Window().Name("windowFactorDefination").Iframe(true)
.Title("Rating Factor Definition")
.Draggable()
.Resizable()
.Modal(true)
.Visible(false)
.Actions(actions => actions.Close())
.Width(850)
.Events(e => e.Close("OnCloseFactorWindow"))
.Position(settings => settings.Top(30))
.Position(settings => settings.Left(100))
.Content(#<text>
#(Html.Kendo().Grid<WeezerSetup.Model.RatingGroup>()
.Name("FactorDefinationGrid")
.Columns(columns =>
{
columns.Bound(c => c.RatingFactorDefinitionID).Visible(false);
columns.Bound(c => c.FactorDefinationDescription).Title("Factor Definition Description").HeaderHtmlAttributes(new { title = "Rating Factor description" });
columns.ForeignKey(b => b.FactorTypeID, (SelectList)ViewBag.FactorList).Width(120).Title("Factor Type").HeaderHtmlAttributes(new { title = "Data type for Rating Factor" });
columns.ForeignKey(c => c.TableID, (SelectList)ViewBag.TableList).Width(300).EditorTemplateName("TableTypeEditorDropDown").Title("SYS_Table").HtmlAttributes(new { id = "drpTableType" });
columns.ForeignKey(c => c.FieldID, (SelectList)ViewBag.FieldList).Width(300).EditorTemplateName("FieldTypeEditorDropDown").Title("SYS_Table_Field").HtmlAttributes(new { id = "drpFieldType" });
columns.ForeignKey(b => b.WildCard, (SelectList)ViewBag.WildCardList).Width(300).Title("Wild Card").HeaderHtmlAttributes(new { title = "Used when any remaining values have the same results" });
columns.Command(command =>
{
command.Edit().Text(" ").HtmlAttributes(new { id = "btnEdit", #style = "text-align:center;", data_toggle = "tooltip", data_placement = "top", title = "Edit" });
}).HeaderTemplate("Action").Width(210);
columns.Command(command => { command.Destroy().Text(" ").HtmlAttributes(new { #class = "fe-delete", title = "DELETE" }); }).HeaderTemplate("Action").HeaderHtmlAttributes(new { title = "Clicking the icon will Delete specific row" });
})
.Resizable(resize => resize.Columns(true))
.Sortable()
.AutoBind(true)
.ToolBar(toolbar => toolbar.Create())
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Filterable()
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Events(events => { events.Edit("onEditGrdMyBenefitsGrid"); events.DataBound("onRowDataBoundGrdMyBenefitsGrid"); })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetRatingFactorDefination", "RateSetup"))
.Model(model =>
{
model.Id(p => p.RatingFactorDefinitionID);
})
.Create(update => update.Action("AddFactorDefination", "RateSetup"))
.Update(update => update.Action("UpdateFactorDefination", "RateSetup"))
.Destroy(delete => delete.Action("DeleteRatingFactorDefinition", "RateSetup").Data("DeleteRecord"))
))
#(Html.Kendo().Tooltip()
.For("#FactorDefinationGrid")
.Filter("th")
.Position(TooltipPosition.Top)
.Width(160)
.Events(events => events.Show("onShow"))
)
</text>))}
So in the above code there are 2 columns Name TableID and FieldID both are dependent column showing as dropdown in the Kendo Grid UI.
Please give me solution to filter both dropdown.
I assume you are looking for a behavior like cascading drop downs.
Refer to this demo link
You need to do the following:-
1) Add cascade from property to editor template of FieldId
.CascadeFrom("TableId")
2) Add a function to your script file to return the selected table id
function filterFields() {
return {
tableId: $("#TableId").val()
};
}
3) Add the script function in your read call
.DataSource(source => {
source.Read(read =>
{
read.Action("ActionName", "ControllerName")
.Data("filterFields");
})
.ServerFiltering(true);
I have a Telerik Kendo Grid and I am adding a record when I click a button:
var dataSource = $("#GridArticulos").data("kendoGrid").dataSource;
dataSource.add({ ArticuloId: articuloId, Nombre: nombre, Precio:
precio, Cantidad: cantidad, Total: total });
dataSource.sync();
The record is added correctly to the grid, but when I click the save button on the grid, nothing happens, the action in the controller is not called, do I need some specific configuration on the grid?, this is what I have now:
#(Html.Kendo().Grid<App.Models.ArticulosListaViewModel>()
.Name("GridArticulos")
.AutoBind(false)
.Columns(columns =>
{
columns.Bound(c => c.ArticuloId).Width("15%");
columns.Bound(c => c.Nombre).Width("35%").ClientFooterTemplate("Total"); ;
columns.Bound(c => c.Cantidad).Width("10%").HtmlAttributes(new { style = "text-align:right" });
columns.Bound(c => c.Precio).Width("10%").Format("{0:C}").HtmlAttributes(new { style = "text-align:right" });
columns.Bound(c => c.Total).Width("10%").Format("{0:C}").HtmlAttributes(new { style = "text-align:right" })
.ClientFooterTemplate("<div align=\"right\">#=kendo.format('{0:C}', sum)#</div>");
columns.Command(command => command.Destroy()).Width("20%");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.ToolBar(toolbar =>
{
toolbar.Save().SaveText("Crear pedido").CancelText("Cancelar");
})
.Selectable(s => s.Mode(GridSelectionMode.Single).Type(GridSelectionType.Cell))
.Scrollable()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "height:550px", #class = "ra-section" })
.DataSource(dataSource => dataSource
.Ajax()
.Aggregates(aggregates =>
{
aggregates.Add(p => p.Total).Sum();
})
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("GridArticulos_Error").RequestEnd("GridArticulos_RequestEnd"))
.Model(model =>
{
model.Id(a => a.ArticuloId);
model.Field(a => a.Nombre).Editable(false);
model.Field(a => a.Cantidad).Editable(false);
model.Field(a => a.Precio).Editable(false);
model.Field(a => a.Total).Editable(false);
})
//.Create(create => create.Action("GuardarPedido", "Pedidos").Data("ObtenerDatos"))
.Update(update => update.Action("GuardarPedido", "Pedidos").Data("ObtenerDatos"))
.Destroy(d => d.Action("EliminarArticulo", "Pedidos"))
)
)
you have your .Create() method commented out. uncomment it and point it to the appropriate controller method and you should be fine
uncomment this line--> //.Create(create => create.Action("GuardarPedido", "Pedidos").Data("ObtenerDatos"))
.Update(update => update.Action("GuardarPedido", "Pedidos").Data("ObtenerDatos"))
.Destroy(d => d.Action("EliminarArticulo", "Pedidos"))
also, your create method is pointed to the same method as your update method on the line below it so you would need to edit the method to point to another method. I can't help there since I don't know what methods you have in your controller
In an MVC project i have the following view where i use the Kendo Grid
<%: Html.Kendo().Grid<Milestone>()
.Name("MilestonesGrid")
.Columns(columns =>
{
columns.Bound(p => p.ContractMilestoneID).Hidden();
columns.Bound(p => p.MilestoneSN).Title("Κωδικός οροσήμου");
columns.Bound(p => p.EstimatedDate).Title("Εκτιμώμενη ημερομηνία");
columns.Bound(p => p.RealDate).Title("Πραγματική ημερομηνία");
columns.Bound(p => p.MilestoneDescription).Title("Περιγραφή");
columns.Bound(p => p.Payment).Title("Πληρωμή");
columns.Bound(p => p.PaymentRate).Title("Ποσοστό πληρωμής");
columns.Bound(p => p.IsCompleted).Title("Έχει ολοκληρωθεί");
columns.Command(command =>
{
command.Edit()
.Text("Επεξεργασία")
.CancelText("Ακύρωση")
.UpdateText("Αποθήκευση");
command.Destroy()
.Text("Διαγραφή");
});
})
.ToolBar(toolbar => toolbar.Create().Text("Προσθήκη νέου οροσήμου"))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable()
.Pageable()
.Filterable()
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Model(model => model.Id(o => o.ContractMilestoneID))
.Model(model => model.Field(o => o.MilestoneSN))
.Model(model => model.Field(o => o.EstimatedDate))
.Model(model => model.Field(o => o.RealDate))
.Model(model => model.Field(o => o.MilestoneDescription))
.Model(model => model.Field(o => o.Payment))
.Model(model => model.Field(o => o.PaymentRate))
.Model(model => model.Field(o => o.IsCompleted))
.Batch(true)
.Create(create => create.Action("CreateMilestone", "Milestones"))
.Read(read => read.Action("DetailsJson", "Milestones",
new { id = ViewBag.ID }))
.Update(update => update.Action("UpdateMilestone", "Milestones"))
.Destroy(delete => delete.Action("DeleteMilestone", "Milestones")))
%>
Also i have a controller where i want to save a new entry in the Kendo Grid.
[HttpPost]
public ActionResult CreateMilestone([DataSourceRequest] DataSourceRequest request,
Milestone milestone)
{
if (milestone != null && ModelState.IsValid)
{
using (TADCEntities database = new TADCEntities())
{
tblSymvaseisOrosima item = new tblSymvaseisOrosima
{
fldEstimatedDate = milestone.EstimatedDate,
fldIsCompleted = milestone.IsCompleted,
fldMilestoneDescription = milestone.MilestoneDescription,
fldMilestoneSN = milestone.MilestoneSN,
fldPayment = milestone.Payment,
fldPaymentRate = milestone.PaymentRate,
fldRealDate = milestone.RealDate,
fldStoixeioYpoergouID = milestone.ElementSubProjectID
};
database.tblSymvaseisOrosima.Add(item);
database.SaveChanges();
return Json(new[] { item }.ToDataSourceResult(request, ModelState));
}
}
return View();
// should also return json
}
The problem is that the Milestone type (the parameter in the controller) is always null even if i enter data when i create a new entry in the grid and press save. Any idea what to do in order to pass the entered data in the milestone parameter? Thank you in advance
As I saw in the Fiddler the parameters is posting with models prefix, thus you must access them like this:
public ActionResult CreateMilestone([DataSourceRequest] DataSourceRequest request,
[Bind(Prefix="models")] List<Milestone> milestons)
{
Milestone milestone = milestons[0];
.
.
.
}