I 'm working on a project and i have a problem. I decide to use kendo grid to help create grid. My grid have a field allow user to upload multiple file in each row.
I want after user upload file, file name will be asign to FileAttach column and send to server when i click save.
One more thing that those files will appear in FileAttach column with a tiny button to delete that file.
I try but it 's not work
I 'm not good at kendo tempalte and javascript so i stuck at this. Hope someone help me, it take me more than a week.
#(Html.Kendo().Grid<TamCao.Core.DomainModel.AcademicDetail>()
.Name("Academic_Grid")
.Columns(columns =>
{
columns.Bound(a => a.ID).Visible(false);
columns.Bound(a => a.PlaceName);
columns.Bound(a => a.From).Format("{0:dd/MM/yyyy}").Width(100);
columns.Bound(a => a.To).Format("{0:dd/MM/yyyy}").Width(100);
columns.Bound(a => a.Degree);
columns.Bound(a => a.DateObtained).Format("{0:dd/MM/yyyy}").Width(180);
columns.Bound(a => a.FileAttach).Template(#<Text> #= FileAttach # </Text>);
columns.Template(#<Text></Text>).ClientTemplate("<input type='file' id='uploadAcademicDetail' multiple=multiple name='uploadAcademicDetail'/>").Width(200).Title("File Attatch"); // Upload File
columns.Command(command => command.Destroy()).Width(90);
})
.ToolBar(toolBar =>
{
toolBar.Create();
toolBar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(a => a.ID);
})
.PageSize(20)
.Read(read => read.Action("AcademicDetail_Read", "AcademicExperience"))
.Create(create => create.Action("AcademicDetail_Create", "AcademicExperience"))
.Update(update => update.Action("AcademicDetail_Update", "AcademicExperience"))
.Destroy(destroy => destroy.Action("AcademicDetail_Destroy", "AcademicExperience"))
)
.Events(e =>
{
e.DataBound("AcademicDataBound");
})
)
</div>
<script type="text/javascript">
function AcademicDataBound(e)
{
$("input[type='file']").kendoUpload({
multiple: true,
async: {
saveUrl: '/AcademicExperience/UploadAcademicDetailAttach',
},
upload: function (e) {
},
success: function (e) {
var grid = $("#Academic_Grid").getKendoGrid();
alert(grid.dataItem($("FileAttach")));
}
});
}
</script>
Related
I have the following Kendo grid:
#(Html.Kendo().Grid<Mizuho.AMS.Models.AMSServiceProcessNotificationModel>()
.Name("grd")
.ToolBar(toolBar =>
{
toolBar.Create();
})
.Sortable()
.Scrollable(a => a.Height("auto"))
.Filterable(s => s.Enabled(false))
.Selectable(s => s.Enabled(false))
.Pageable(p => p.Enabled(true).Refresh(true).PageSizes(new List<string> { "all", "10", "15", "20", "50" }))
.HtmlAttributes(new { style = "width: 100%;" })
.Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("NotificationEditor").Window(w => w.Width(700)))
.Columns(columns =>
{
columns.Bound(s => s.ProcessId).Width(90);
columns.Bound(s => s.NotificationType).Width(140);
columns.Bound(s => s.NotificationAction).Width(140);
columns.Bound(s => s.Parameters).Width(680);
columns.Command(cmd => { cmd.Edit(); cmd.Destroy(); });
})
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.PageSize(15)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(s => s.ID);
})
.Read(read => read.Action("Read", "Notification"))
.Create(create => create.Action("Create", "Notification"))
.Update(update => update.Action("Update", "Notification"))
.Destroy(destroy => destroy.Action("Destroy", "Notification"))
)
.Resizable(resize => resize.Columns(true))
)
As you can see, I am using a popup dialog to edit a row. This creates a Kendo window with an update button, which will cause the Update method of the Notification controller to fire. If there is an error there, the error_handler specified above is called. This is it:
function error_handler(e) {
if (e.errors) {
var message = "";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
}
}
I display any errors, and the Kendo window is dismissed (actually, the order is, dismiss window, then errors are displayed).
What I want to do instead:
If there is an error after the user clicks the Update button, call the update method, get the error and display it, and NOT DISMISS THE WINDOW. This will allow the user to correct the error and try again.
Thanks for reading.
I'm trying to limit the dropdowns in my kendo grid to only contain Products that have been previously mapped to the company chosen in another cell in the row.
I've used a dynamic drop down editor template approach.
However, the ID passed to getCompanyId() is always null and therefore my dropdowns are always null.
View:
#(Html.Kendo().Grid<XXXAppXXX.Models.WeeklyRailPlan>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.WeekNumber);
columns.Bound(c => c.Company).ClientTemplate("#=(data.Company) ? Company.Name : 'Select Company...'#");
columns.Bound(c => c.ServiceCode);
columns.Bound(o => o.Product)
.ClientTemplate("#= (data.Product) ? Product.Name : 'Select Product'#")
.EditorTemplateName("DynamicDropDownList");
//etc
})
.ToolBar(toolbar => {
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Filterable()
.Events(ev => ev
.Remove(#"function(e){setTimeout(function(){$('#grid').data('kendoGrid').dataSource.sync()})}")
)
.Sortable(sortable => {
sortable.SortMode(GridSortMode.SingleColumn);
})
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Sort(p => { p.Add("WeekNumber").Descending(); })
.Model(model => model.Id(p => p.ID))
.Read(read => read.Action("WeeklyRailPlans_Read", "WeeklyRailPlanGrid"))
.Create(create => create.Action("WeeklyRailPlans_Create", "WeeklyRailPlanGrid"))
.Update(update => update.Action("WeeklyRailPlans_Update", "WeeklyRailPlanGrid"))
.Destroy(destroy => destroy.Action("WeeklyRailPlans_Destroy", "WeeklyRailPlanGrid"))
)
)
EditorTemplate called DynamicDropDownList.cshtml
<script type="text/javascript">
function getCompanyId() {
return { CompanyID: '#=ID#' };
}
</script>
#(Html.Kendo().DropDownList()
.Name("Product")
.DataValueField("ID")
.DataTextField("Name")
.DataSource(ds => ds
.Read(read => read.Action("GetProductsForCompany", "Products").Data("getCompanyId")))
)
Controller method GetProductsForCompany (this is always receiving null)
public ActionResult GetProductsForCompany(int CompanyID)
{
return Json(db.Products.Where(e => e.Companies.Any(t =>t.ID == CompanyID)), JsonRequestBehavior.AllowGet);
}
I use code like this:
<script type="text/javascript">
function getCompanyId() {
var gview = $('#grid').data("kendoGrid");
var selectedItem = gview.dataItem(gview.select());
return { CompanyID: selectedItem.ID };
}
</script>
This solution required was:
function getCompanyId() {
var grid = $('#grid').data('kendoGrid');
var dataItem = grid.dataItem(grid.table.find('.k-edit-cell').parents('tr'))
return { CompanyID: dataItem.Company.ID };
}
I have this telerik grid in a asp.net mvc project
<div class="actualGrid" id="actualGrid">
#(Html.Kendo().Grid<AVNO_KPMG.Models.Bench>() //Bench Grid
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.name).Title("Bench").Filterable(ftb => ftb.Cell(cell => cell.Operator("startswith"))).Width(100);
columns.Bound(p => p.freeSeats).Title("Free Seats").Width(200).Filterable(ftb => ftb.Cell(cell => cell.Operator("gte"))).HtmlAttributes(new { #class = "FreeSeats" })
.ClientTemplate("<div class='barthingy'><div class='bars_text'><div class='seatsText'><span class=\"bookNotfull\"></span> <b>#=bookedSeats#</b> USED SEATS</div><div class='seatsText'><span class=\"bookfull\"></span> <b>#=freeSeats#</b> TOTAL OFSEATS</div></div><div id='bigbar'><div class='bigbar' style='width:100%; float:left; background-color:rgb(142, 188, 0);'><div ' style='float:right; width:#=bookedSeats *100 / seatsCount#%; background-color:rgb(255, 99, 71); height:16px ' class='b_#=name#' id='temp-log'></div></div></div></div>");
//buttons
columns.Command(command => { command.Custom("checkBench1 ").Text(" AM ").Click("doCheckIn"); command.Custom("checkBench 2").Text(" PM ").Click("doCheckIn"); command.Custom("checkBench3").Text("All Day").Click("doCheckIn"); }).HtmlAttributes(new { #class = "comms#=freeSeats# freeAM#=seatsCount - (bookings_am + bookings_allday)# freePM#=seatsCount - (bookings_pm + bookings_allday)# freeALLDAY#=freeSeats#" }).Title("Check in").Width(200);
})
.Pageable()
.Sortable()
.Scrollable(scrolling => scrolling.Enabled(false))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
//.HtmlAttributes(new { style = "height:530px;" })
.Events(events => events.DataBound("onDataBound"))
.DataSource(dataSource => dataSource
.Ajax()
//.Sort(sort => sort.Add("freeSeats").Ascending())
.PageSize(10)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.id))
.Read(read => read.Action("GetBenches", "Deskcheckin"))
)
)
</div>
Everytime i press on of the buttons in the command column, the url gets a # in front of it, even if i set the buttons to do nothing.
my url is something like
http://www.aaaaaa.com/stuff
When i press one of the buttons i get
http://www.aaaaaa.com/stuff#
How can i disable this?
Please try with the below code snippet. For custom command button grid generate anchor control for same. By default it set href='#' and I have replaced it with href='javascript:void(0)'.
<div>
#(Html.Kendo().Grid<MvcApplication1.Models.Student>()
.Name("grid")
.Columns(columns =>
{
..........
..........
columns.Command(command => { command.Custom("checkBench1").Text("AM").Click("doCheckIn"); }).Title("Check in").Width(200);
})
.Events(events => events.DataBound("onDataBound"))
..........
..........
)
</div>
<script>
function doCheckIn() {
alert('a');
}
function onDataBound(arg) {
$("#.k-grid-checkBench1").attr('href', 'javascript:void(0)');
}
</script>
Let me know if any concern.
I'm using the Kendo Grid control to display some data and it's working OK. This is the code:
#(Html.Kendo().Grid<MyModel>()
.Name("MyGrid")
.ToolBar(toolbar =>
{
toolbar.Create().Text("Add New Line").HtmlAttributes(new { #Class = "btn btn-primary" });
})
.Columns(columns =>
{
columns.Bound(p => p.Description).HtmlAttributes(new {style = "font-size: 9pt;"});
columns.Bound(p => p.Value);
columns.Command(cmd =>
{
cmd.Edit();
cmd.Destroy();
}).Width(200);
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Selectable(s => s.Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Row))
.DataSource(data => data
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Id))
.ServerOperation(false)
.Read(read => read.Action("ReadAction", "MyController"))
.Create(create => create.Action("CreateAction", "MyController"))
.Update(update => update.Action("UpdateAction", "MyController"))
.Destroy(delete => delete.Action("DeleteAction", "MyController"))
))
The code above is working without any problem. Now, what I'm trying to implement is to display the same data using the MVVM pattern. I mean, I would like to have the same operations (create, update, delete) in my viewmodel without calling the server actions of my controller as the code above does.
I have google it for a while but without any luck.
Any help would be very appreciate
I have a question based on my current situation, I have a grid with ClientDetail / Child grid inside of it. In my parent grid there is a custom command button, let say...
"columns.Command(
command => { command.Custom("Edit").Click("showEdit"); command.Destroy();
}).Width(160);"
and also i had my custom command button as well in my child grid, let say...
"columns.Command(
command => { command.Custom("Edit").Click("showSubEdit"); command.Destroy();
}).Width(160);"
Those 2 custom command should call different function which is "showEdit" & "showSubEdit". The problem is, every time custom command in child grid triggered, it always calls its parent's function which is "showEdit", however the child grid should call "showSubEdit".
Is there something i missed ?
NB :
function showEdit(e) {
...
}
function showSubEdit(e) {
...
}
Grid Code :
<div>
#(Html.Kendo().Grid<ActivityModel>()
.Name("GridActivity")
.Columns(columns =>
{
//columns.Template(t => { }).Title("No").ClientTemplate("#= renderNumber(data) #").Width(50);
columns.Bound(c => c._id).Visible(false);
columns.Bound(c => c.ActivityType.TypeTitle).Title("Type").Width(80);
columns.Bound(c => c.ActivityTitle).Title("Title").Width(120);
columns.Bound(c => c.DependenciesStr).Title("Dependencies").Width(120);
columns.Bound(c => c.ResourcesStr).Title("Resources").Width(120);
columns.Bound(c => c.FromStr).Title("From");
columns.Bound(c => c.ToStr).Title("To");
columns.Bound(c => c.Status).Title("Status").Width(90).Format("{0:0.00} %").Width(85);
columns.Bound(c => c.Weight).Title("Weight").Format("{0:0.00} %").Width(85);
columns.Command(command => { command.Custom("Edit").Click("showEdit"); command.Destroy(); }).Width(160);
})
.HtmlAttributes(new { style = "height: 290px;" })
.Groupable()
.Scrollable()
.Sortable()
.Filterable()
.ClientDetailTemplateId("template")
.Pageable(x => x.PageSizes(new int[] { 10, 20 }).Refresh(true))
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(c => c.Id(p => p._id))
.Read(read => read.Action("ProjectActivities_Read", "Project", new { projectId = ViewBag.ProjectId }))
.Destroy(destroy => destroy.Action("ProjectActivities_Destroy", "Project", new { projectId = ViewBag.ProjectId }))
)
.Events(x => x.DataBound("resetRowNumber"))
)
</div>
<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("Sub Activity").Content(#<text>
#(Html.Kendo().Grid<ActivityModel>()
.Name("GridChild_#=_id#")
.Columns(columns =>
{
columns.Bound(x => x._id).Visible(false);
columns.Bound(x => x.ActivityType.TypeTitle).Title("Type");
columns.Bound(x => x.ActivityTitle).Title("Title").Width(150);
columns.Bound(x => x.DependenciesStr).Title("Dependencies").Width(150);
columns.Bound(x => x.ResourcesStr).Title("Resources").Width(150);
columns.Bound(x => x.FromStr).Title("From");
columns.Bound(x => x.ToStr).Title("To");
columns.Bound(x => x.Status).Title("Status").Width(90).Format("{0:0.00} %").Width(85);
columns.Bound(x => x.Weight).Title("Weight").Format("{0:0.00} %").Width(85);
columns.Command(command => { command.Custom("Edit").Click("showEditSub"); command.Destroy(); }).Width(160);
})
.Pageable(x => x.PageSizes(new int[] { 5, 10 }).Refresh(true))
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Model(x => x.Id(y => y._id))
.Read(read => read.Action("ProjectSubActivities_Read", "Project", new { projectId = ViewBag.ProjectId, activityId = "#=_id#" }))
.Destroy(destroy => destroy.Action("ProjectSubActivities_Destroy", "Project", new { projectId = ViewBag.ProjectId, activityId = "#=_id#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate())
</text>
);
}).ToClientTemplate())
</script>
I got around the bubbling by checking if the element shown by the first command event is visible:
function showDetailsLevel(e) {
e.preventDefault();
originatingId = this.dataItem($(e.currentTarget).closest("tr")).Id
var wnd = $("#Details").data("kendoWindow");
if (!$("#Details").is(":visible")) {
wnd.center();
wnd.open();
var grid = $("#DetailGrid").data("kendoGrid");
grid.dataSource.read();
}
}