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
Related
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;
}
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 kendo grid in which I want to form delete button to pass the details of the row to the controller (as I am using mvc). Then I will use these details to delete the row from the database.
I searched in kendo website and I found the part for the delete or destroy call but I don't know how to pass these details of the row to the controller.
#(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("Grid")
.Columns(columns => {
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice).Width(140);
columns.Bound(p => p.UnitsInStock).Width(140);
columns.Bound(p => p.Discontinued).Width(100);
columns.Command(command => command.Destroy()).Width(110);
})
.ToolBar(toolbar => {
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Navigatable()
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(20)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ProductID))
.Create("Editing_Create", "Grid")
.Read("Editing_Read", "Grid")
.Update("Editing_Update", "Grid")
.Destroy("Editing_Destroy", "Grid")
)
)
My grid:
<div id="grid">
#(Html.Kendo().Grid<dynamic>()
.Name("BrowseGrid")
.Columns(columns =>
{
foreach (System.Data.DataColumn c in Model.Grid.Columns)
{
columns.Bound(c.ColumnName).EditorTemplateName("String");
}
columns.Command(command =>
{
command.Destroy();
command.Custom("").Text("editteam").HtmlAttributes(new { id = "editteam", onClick = "editRow()" });
});
})
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model =>
{
//Define the model
foreach (System.Data.DataColumn column in Model.Grid.Columns)
{
model.Field(column.ColumnName, column.DataType);
model.Id("Id");
}
})
.Read(read =>
read.Action("BrowseGrid", "Configuration")
)
.Destroy( update => update.Action("Delete", "Configuration"))
//Data("{nodeID:"+#Model.nodeID+"}"
)
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new int[] { 10, 100, 1000, 10000, 100000, 1000000 })
.ButtonCount(10)
)
)
Please change to:
.Destroy(update => update.Action("Process_Destroy", "controller name"))
and in controller,
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Process_Destroy([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
{
if (product != null)
{
//write your code for delete action;
}
return Json(ModelState.ToDataSourceResult());
}
This will work.
I am assuming you only need the id of the row to delete it, but I think you can send the full model of the selected row. I am sending both.
Like this:
.Destroy(d => d.Action("controllerMethod", "controllerName").Data("jsFunction"))
And in javascript:
function jsFunction() {
var grid = $("#BrowseGrid").data("kendoGrid");
var id = grid.dataItem(grid.select()).Id;
return {
id: id
};
}
Your controller method should receive the parameter:
public ActionResult controllerMethod(string id)
I'm using Kendo UI Web for asp.net mvc. I generate a pop-up window via a grid command button. After the closing of this pop-up window, I want the grid to be refreshed.
Close event on pop-up window:
function ClosingRateWindow(e) {
var grid = $('#ContractDetailOrderEventGrid').data("kendoGrid");
grid.dataSource.read();}
The grid is undefined at this time.
Kendo Window definition:
#(Html.Kendo().Window()
.Name("Rates")
.Title("Rates")
.Visible(false)
.Modal(true)
.Draggable(true)
.Width(850)
.Height(1200)
.Events(x => x.Close("ClosingRateWindow"))
)
Javascript to open window (a partial view is returned):
wnd.refresh({
url: BASE_APP_URL + "ContractRateAdmin/OpenContractRate/",
data: { data: data },
traditional: true
});
wnd.center();
wnd.open();
Grid Definition:
#(Html.Kendo().Grid<TMS.MVC.TIMS.Models.Admin.Contract.ContractOrderEventGridModel>()
.Name("ContractDetailOrderEventGrid")
.Columns(columns =>
{
columns.Command(o =>
{
o.Destroy();
o.Edit();
}).Width(100).Title("Commands");
columns.Command(command =>
{
command.Custom("Rates").Click("ShowRates");
}).Title("Rates").Width(120);
columns.Bound(o => o.ContractId).Hidden(true);
columns.Bound(o => o.OrderTypeId).Hidden(true);
//columns.Bound(o => o.ActiveRateMissing).Width(70).Title("Missing Rates?");
columns.Bound(o => o.OrderLevelFlag).Width(50).Title("Order Level").EditorTemplateName("ContractOE_OrderLevelFlag");
columns.Bound(o => o.Active).Width(80).Title("Active").EditorTemplateName("ContractOE_Active");
columns.Bound(o => o.InvoiceDescription).Width(150).Title("Invoice Desc");
columns.Bound(o => o.SourceContainerOwnerNameDisplay).Width(150).Title("Src Cont Owner").EditorTemplateName("ContractOE_SourceContainerOwner");
columns.Bound(o => o.DestContainerOwnerNameDisplay).Width(150).Title("Dest Cont Owner").EditorTemplateName("ContractOE_DestContainerOwner");
columns.Bound(o => o.SourceContainerTypeName).Width(150).Title("Src Cont Type").EditorTemplateName("ContractOE_SourceContainerTypeName");
columns.Bound(o => o.DestContainerTypeName).Width(150).Title("Dest Cont Type").EditorTemplateName("ContractOE_DestContainerTypeName");
columns.Bound(o => o.SourceContainerName).Width(150).Title("Src Container").EditorTemplateName("ContractOE_SourceContainerName");
columns.Bound(o => o.DestContainerName).Width(150).Title("Dest Container").EditorTemplateName("ContractOE_DestContainerName");
columns.Bound(o => o.EventAliasName).Width(150).Title("Event").EditorTemplateName("ContractOE_EventAliasName");
columns.Bound(o => o.ProductName).Width(150).Title("Product").EditorTemplateName("ContractOE_ProductName");
columns.Bound(o => o.OrderByNameDisplay).Width(150).Title("Order By").EditorTemplateName("ContractOE_OrderBy");
columns.Bound(o => o.OrderTypeName).Width(150).Title("Order Type").EditorTemplateName("ContractOE_OrderTypeName");
columns.Bound(o => o.EmployeeDisplay).Width(150).Title("Employee").EditorTemplateName("ContractOE_EmployeeDisplay");
columns.Bound(o => o.CarrierName).Width(150).Title("Carrier").EditorTemplateName("ContractOE_CarrierName");
})
.Events(e => e
.Save("Contract_Save")
//.Remove("ContractOrderEventGrid_Remove")
.DataBound("Contract_DataBound"))
.Scrollable(scrolling => scrolling.Enabled(true).Height("300px"))
.ToolBar(toolbar => {
if (Model.DetailModel.ContractAdminDetailPermissionModel.AddOrderEvent_Button_Visible == true)
toolbar.Create().Text("Add");
})
.HtmlAttributes(new { style = "width: 1200px" })
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable(sorting => sorting.Enabled(true))
.Pageable(paging => paging.Enabled(false))
.Resizable(resizing => resizing.Columns(true))
.Filterable(filtering => filtering.Enabled(true))
.Groupable(grouping => grouping.Enabled(true))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.ContractOrderEventId);
model.Field(x => x.ActiveRateMissing).Editable(false);
model.Field(x => x.ContractId).Editable(false);
model.Field(x => x.OrderTypeId).Editable(false);
model.Field(x => x.Active).Editable(true).DefaultValue("Y");
model.Field(x => x.OrderLevelFlag).Editable(true).DefaultValue("N");
model.Field(x => x.InvoiceDescription).Editable(true).DefaultValue("Enter Invoice Description");
model.Field(x => x.SourceContainerOwnerNameDisplay).Editable(true).DefaultValue("ALL");
model.Field(x => x.DestContainerOwnerNameDisplay).Editable(true).DefaultValue("ALL");
model.Field(x => x.SourceContainerTypeName).Editable(true).DefaultValue("ALL");
model.Field(x => x.DestContainerTypeName).Editable(true).DefaultValue("ALL");
model.Field(x => x.SourceContainerName).Editable(true).DefaultValue("ALL");
model.Field(x => x.DestContainerName).Editable(true).DefaultValue("ALL");
model.Field(x => x.EventAliasName).Editable(true).DefaultValue("ALL");
model.Field(x => x.ProductName).Editable(true).DefaultValue("ALL");
model.Field(x => x.OrderByNameDisplay).Editable(true).DefaultValue("ALL");
model.Field(x => x.OrderTypeName).Editable(true).DefaultValue("ALL");
model.Field(x => x.EmployeeDisplay).Editable(true).DefaultValue("ALL");
model.Field(x => x.CarrierName).Editable(true).DefaultValue("ALL");
})
.Events(x =>
{
// x.RequestEnd("RefreshContractDetailOrderEventGrid");
//x.Error("ContractDetailOrderEventGrid_Error");
})
.Create(update => update.Action("CreateContractOrderEvent", "ContractGrid", new { selectedContractId = Model.DetailModel.ContractId }))
.Read(read => read.Action("ReadContractOrderEvent", "ContractGrid", new { contractId = Model.DetailModel.ContractId }))
.Update(update => update.Action("UpdateContractOrderEvent", "ContractGrid", new { contractId = Model.DetailModel.ContractId }))
.Destroy(update => update.Action("DestroyContractOrderEvent", "ContractGrid"))
))
Any ideas on how to do this?
Basically you need to use the close event of the Window and the refresh method of the Grid or I guess you need to use the dataSource.read() method which will refresh the data of the Grid :)
wnd.bind('close',function(){
$('#Rates').data().kendoGrid.dataSource.read(); // or
$('#Rates').data().kendoGrid.refresh();
})
The grid variable is undefined in the popup, because it is defined in the parent window;
so you need to do the following:
var grid = window.parent.$("#grid").data("kendoGrid");
grid.dataSource.read()
\I do see a lot of responses here concerned with the undefined error. I am attempting to do the same thing here. My resolution to the issue was to attach a function to the close event of the editor window.:
.Editable(a => a.Mode(GridEditMode.PopUp).Window(q => q.Title("New Stage").Events(e => e.Close("UpdateStages"))))
And then the function that is called is:
function UpdateStages() {
$("#StagesForCourse").data("kendoGrid").dataSource.read();
}
I dont worry about trying to take in the variable, instead i call the grid directly and tell it to read the dataSource
Can you try;
function ClosingRateWindow(e) {
var grid = $('#ContractDetailOrderEventGrid').data("kendoGrid");
grid.refresh();
}
I know this answer is probably late. But if you are getting content from another URL. You need to set .Iframe(true). Found this out after hours of debugging. They really have very poor documentation on this.