I've been searching and and I cannot find a thread or answer for what I'm doing specifically. I have a site where a user will be creating a record called 'ManualProcess'. In the pop-up they will enter general information about the record and then with the Upload() select files to be uploaded and associated to this main record. The files will be stored in a separate table name 'ManualPrcoessDeocuments' with a FK relationship back to the 'ManualProcess' record.
What I'm trying to do is have the HttpPostedFileBase[] object be passed back to the controller along with the 'ManualProcess' record. I have been able to get it to call and pass a value using the async option but that occurs before they have sent the main record data. So ido not have the main record id to associate the documents with.
Below is the grid code.
@(Html.Kendo().Grid(Model).Name("ManualWorkflowProcess").Columns(c =>
{
c.Bound(e => e.Name);
c.Bound(e => e.Description);
c.Bound(e => e.ApprovalProcessName);
c.Bound(e => e.Active).ClientTemplate("<
input
type
=
'checkbox'
disabled
=
'disabled'
value
=
'#= Active #'
" + "# if (Active) { #" + "
checked
=
'Active'
" + "# } #" + "/>").Width(100);
c.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(200);
})
.ToolBar(toolbar => toolbar.Create().Text("Create New Process"))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ManualProcessPopUp").Window(w => w.Width(700)))
.Pageable(pager => pager.AlwaysVisible(false).PageSizes(new List<
object
> { 5, 10, 20, 100 }))
.Sortable()
.Filterable()
.Groupable()
.Events(events => events.Edit("Edit"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model => model.Id(p => p.Id))
.Create(update => update.Action("EditingPopup_Create", "ManualApprovalProcesses"))
.Read(read => read.Action("EditingPopup_Read", "ManualApprovalProcesses"))
.Update(update => update.Action("EditingPopup_Update", "ManualApprovalProcesses"))
.Destroy(update => update.Action("EditingPopup_Destroy", "ManualApprovalProcesses"))
))
Below is the Upload() code in the pop-up template
<
div
class
=
"editor-label"
>
@Html.Label("Files", htmlAttributes: new { @class = "control-label col-md-10" })
</
div
>
<
div
class
=
"editor-field"
>
@(Html.Kendo().Upload().Name("FileUploads").HtmlAttributes(new { aria_label = "files" })))
</
div
>
Below is my controller code.
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult EditingPopup_Update([DataSourceRequest] DataSourceRequest request, ManualApprovalProcess manualProcess, HttpPostedFileBase[] fileUploads)
{
if
(manualProcess !=
null
&& ModelState.IsValid)
{
this
.Update(manualProcess);
}
return
Json(
new
[] { manualProcess }.ToDataSourceResult(request, ModelState));
}
So I want to have the file data passed back to the controller so I can create the main record and then use that id and loop over the documents and use that new id when creating the document records.
If this possible the way I'm trying to achieve this? I can;t do the async call because I will be missing come data that I need to properly upload and create the document records as well as upload them to the correct location in Azure.
Hi,
I declared the below Kendo grid with checkbox column. Below is the javascript script
@model IEnumerable<NotificationTypesModel>
<script type="text/javascript">
function CloseNotificationPopup() {
$('#ManageNotifications').data('kendoWindow').close();
}
function OnNotificationsBound(e) {
e.preventDefault();
var grid = this;
var rows = grid.items();
$(rows).each(function (e) {
var row = this;
var dataItem = grid.dataItem(row);
if (dataItem.IsRowSelected == true) {
grid.select(row);
//dataItem.IsRowSelected = false;
}
});
}
function SaveNotificationPreferences() {
var items = [];
var notificationTypesGrid = $('#NotificationTypes').data("kendoGrid");
for (var i = 0; i < notificationTypesGrid.selectedKeyNames().length ; i++) {
var currentDataItem = notificationTypesGrid.selectedKeyNames()[i];
items.push(currentDataItem);
}
}
</script>
The below is the kendo grid
@(Html.Kendo().Grid(Model)
.Name("NotificationTypes")
.Columns(columns =>
{
columns.Select().Width(39).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:center", tabindex = "1" });
columns.Bound(p => p.NotificationTypeID).Visible(false);
columns.Bound(p => p.IsRowSelected).Visible(false);
columns.Bound(p => p.NotificationTypeName);
})
.Pageable(page =>
{
page.PageSizes(true);
page.PreviousNext(true);
page.Input(true);
page.PageSizes(new int[] { 5, 10, 20, 50, 100 });
})
.Sortable()
.PersistSelection()
.Events(e => e.DataBound("OnNotificationsBound"))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(false)
.PageSize(5)
.Model(model => model.Id(p => p.NotificationTypeID))
.ServerOperation(false)
)
)
Below is the class I am using to bind
public class NotificationTypesModel
{
public Guid NotificationTypeID { get; set; }
public string NotificationTypeCode { get; set; }
public string NotificationTypeName { get; set; }
public bool IsRowSelected { get; set; }
}
When the page loads I am selecting the rows based on the data retrieved from the database. This is done inside the OnNotificationsBound event.
And on the page there is a button which will save the selections back to the database. The issue I am having is in the SaveNotificationPreferences() method I am not getting the records of selections from all the pages. I am unable to figure out the issue.
I am using the below version of Kendo.
2017.3.1018.545
I have a grid that I want to have a secondary grid show if the user clicks the detail. Normally I have a databound method that is called on the parent grid to color the rows based on the data there but I don't seem to be able to do this for the parent grid if I use the client detail template for the secondary grid. Am I missing something? here is the grid declarations for both grids. It works if i remove the client detail grid.
@(Html.Kendo().Grid<tbl_Quote_Scheduled_Locations>()
.Name("locations")
.DataSource(datasource => datasource
.Ajax()
.Model(model => model.Id(p => p.Id))
.Read(read => read.Action("LocationsGetList", "Import").Data("onLocationRead"))
.Update(update => update.Action("UpdateLocation", "Import"))
.Destroy(update => update.Action("DeleteLocation", "Import"))
.Aggregates(agg =>
{
agg.Add("LocationName", typeof(int?)).Count();
agg.Add(p => p.TIV).Sum();
})
.Events(e => e.RequestEnd("onChange"))
)
.Columns(columns =>
{
columns.Bound(p => p.LocationName).Title("Location Name").ClientFooterTemplate("Count: #=count#");
columns.Bound(p => p.Address).Title("Address");
columns.Bound(p => p.City).Title("City");
columns.Bound(p => p.State).Title("State");
columns.Bound(p => p.Zip).Title("Zipcode");
columns.Bound(p => p.TIV).Title("TIV").Format("{0:c}").ClientFooterTemplate("Total TIV: #=kendo.toString(sum, 'C')#");
columns.Bound(p => p.Error).Hidden(true);
columns.Command(command =>
{
command.Edit();
command.Destroy();
});
})
.Events(e => e
.DataBound("onLocationsGridBound")
)
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("Location"))
.ClientDetailTemplateId("errorTemplate")
)
<script id="errorTemplate" type="text/kendo-tmpl">
@(Html.Kendo().Grid<ReturnLocationErrors_Result>()
.Name("error_#=Id#")
.Columns(col =>
{
col.Bound(o => o.LocationId).Hidden(true);
col.Bound(o => o.ErrorDetail);
})
.DataSource(s => s
.Ajax()
.Read(read => read.Action("GetLocationErrors", "Import", new {locationId = "#=Id#"}))
)
.ToClientTemplate()
)
</script>
function onLocationsGridBound() {
var data = this._data;
for (var x = 0; x < data.length; x++) {
var dataItem = data[x];
var tr = $("#locations").find("[data-uid='" + dataItem.uid + "']");
console.log(tr);
var cell = $("td:nth-child(7)", tr);
if (cell[0].textContent == "1") {
tr.addClass("ErrorColor");
}
}
}
Hello community!
I have a problem with my grid and the popup-editing feature.
In my popup there is another grid which needs the email address from the selected row from parent grid (to get the right data in the child grid).
I already tried the "grid.dataItem(grid.select())"-Function. But its return false.
Maybe I misunderstand the problem.
This is my Main-Grid:
@(Html.Kendo().Grid<NPHE2016Management.Models.MailboxViewModel>()
.Name("mailboxes")
.Columns(columns =>
{
columns.Bound(c => c.mailboxID).Hidden();
columns.Bound(c => c.upn).Hidden();
columns.Bound(c => c.mailboxType);
columns.Bound(c => c.firstName);
columns.Bound(c => c.lastName);
columns.Bound(c => c.email);
columns.Bound(c => c.mailboxSize).Title("Mailbox Größe (MB)");
columns.Command(command => { command.Edit().Text(" "); command.Destroy().Text(" "); }).Width(150);
})
.ToolBar(toolbar => toolbar.Create())
.HtmlAttributes(new { style = "height: 550px;" })
.Scrollable()
.Sortable()
.Selectable(x => x.Mode(GridSelectionMode.Single))
.Editable(editable => editable
.Mode(GridEditMode.PopUp)
.TemplateName("MailboxTemplate")
.Window(window => window.Width(1000).HtmlAttributes(new { style = "width:700px;" }))
)
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.mailboxID))
.Read(read => read.Action("MailboxRead", "Home"))
.Create(update => update.Action("MailboxCreate", "Home")).Events(ev => ev.Error("onErrorMailbox"))
.Update(update => update.Action("MailboxUpdate", "Home")).Events(ev => ev.Error("onErrorMailbox"))
.Destroy(update => update.Action("MailboxDelete", "Home")).Events(ev => ev.Error("onErrorMailbox"))
.PageSize(20)
)
.Events(e =>
{
e.Edit("onEdit");
e.Remove("onRemove");
e.Change("onRowChange");
})
)
Thank you very much.
Best regards
Patrick
Hi,
I'm creating grid with dynamic model structure. But i could not use ForeignKey for dropdowns.
i'am using same viewdata method for non-dynamic grid structure and its working. Because i know model name and model tree.
I want to use dropdowns with dynamic grid structure.
var countries = _adminBusinessLayer.Get("sys_Address_Countries"); //Countries for dropdown
ViewData["Countries"] = countries;
@(Html.Kendo().Grid<
dynamic
>()
.Name("Grid")
.Columns(columns =>
{
foreach (System.Data.DataColumn column in Model.Columns)
{
var c = columns.Bound(column.ColumnName);
if (column.ColumnName == "CountryID")
{
//columns.ForeignKey(d => d.CountryID, (System.Collections.IEnumerable)ViewData["Countries"], "CountryID", "countryNameTr").HeaderTemplate("<
i
class
=
'fa fa-user'
></
i
> Country");
}
}
...
Hi All,
I'm having problems when trying to add a clickable hyperlink to my header template on my grid. The idea is to add a hyperlink with the text of ClientName from the dataitem that will call my controller and pass the ClientCode of the underlying data item.
.Columns(columns =>
{
columns.Bound(u => u.ClientName)
.ClientGroupHeaderTemplate(Html.ActionLink("\"<#= ClientName#>\"", "blalbalba", "blabla", new { clientCode = "<#= ClientCode #>" }).ToString());
columns.Bound(u => u.Status).Width("50px").Title("Collat").ClientTemplate("<
i
class
=
'#= Status ? '
fa fa-check fa-3x red-text' : 'fa' #'/>");
columns.Bound(u => u.Quantity).Width("100px");
columns.Bound(u => u.Security).Title("Security");
columns.Bound(u => u.Value).Format("{0:C}")
.ClientGroupFooterTemplate("#=kendo.toString(sum, '£0.00') #")
.ClientFooterTemplate("#= kendo.toString(sum, '£0.00') #").Width("100px");
columns.Bound(u => u.CollatValue).Format("{0:C}")
.ClientGroupFooterTemplate("#=kendo.toString(sum, '£0.00') #")
.ClientFooterTemplate("#= kendo.toString(sum, '£0.00') #").Title("Collat. Value").Width("100px");
})
.NoRecords("No records found")
.Pageable(pageable => pageable.Refresh(true))
.Sortable()
.Navigatable()
.AutoBind(true)
.DataSource(dataSource => dataSource
.Ajax()
.Aggregates(aggregates =>
{
aggregates.Add(p => p.Value).Sum();
aggregates.Add(p => p.CollatValue).Sum();
}).Group(group => group.Add(x => x.ClientName))
.PageSize(100)
cheers
Hi Team,
I have a custom add new row button on each row, which adds a new row adjacent to the current row which works fine with the below js code:
var grid = $("#grid").data("kendoGrid");
customRowDataItem = this.dataItem($(e.currentTarget).closest("tr"));
currentCommissionMemoId = customRowDataItem.uidCommissionMeemoBusiness;
var idx = grid.dataSource.indexOf(customRowDataItem);
console.log(idx);
var newItem = grid.dataSource.insert(idx, {});
var newRow = grid.items().filter("[data-uid='" + newItem.uid + "']");
grid.editRow(newRow);
The issue is, I am trying to do the same after grouping the grid data using the drag and drop grouping option. The add new row acts weird after grouping,
1. New row is not added adjacent to the current row
2. When trying to add a new row in a different page (grid is pageable), does not add a new row at all.
My primary intention is to add a new row inside the group after grouping the kendo grid data, is this possible?
Thank you in advance,
Sam
Hello,
I would like to know if i can add an ActionLink in a column in my DetailTemplate:
The only way I've found is by using a Template , for exemple :
.Columns(col => {
col.Bound(p => p.Etat).Template(@<text>@Html.ActionLink("Edit", "Edit")</text>);
})
But like i'm already in a DetailTemplate , i get an error when i try to do this :
.DetailTemplate(
@<text>
@(Html.Kendo().Grid<Affaire>()
.Name("Affaires_" + item.Id)
.Columns(col => {
col.Bound(p => p.Name).Template(@<text>@Html.ActionLink("Edit", "Edit")
</text>)
Is there another way to make this link work ?
Thanks
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
namespace
webArta.Models
{
public
class
ASoratModel
{
public
long
id {
get
;
set
; }
public
String name {
get
;
set
; }
public
String title {
get
;
set
; }
}
}
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Data.SqlClient;
using
System.Linq;
using
System.Web;
namespace
webArta.Models
{
public
class
ASoratService
{
private
String sqlCnStr = functions.GetConnectionString(
false
);
public
List<ASoratModel> Read()
{
List<ASoratModel> data =
new
List<ASoratModel>();
using
(SqlConnection connection =
new
SqlConnection(sqlCnStr))
{
connection.Open();
using
(SqlCommand command =
new
SqlCommand(
"select * from [test]"
, connection))
{
using
(SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
while
(reader.Read())
{
ASoratModel m =
new
ASoratModel();
m.id = (
long
)reader[
"id"
];
m.title = (
string
)reader[
"title"
];
m.name = (
string
)reader[
"name"
];
data.Add(m);
}
}
}
}
return
data;
}
public
void
Create(ASoratModel model)
{
model.name =
""
;
model.title =
""
;
String sql =
"INSERT INTO [test] (name,title) VALUES ('"
+ model.name +
"','"
+ model.title +
"')"
;
using
(SqlConnection connection =
new
SqlConnection(sqlCnStr))
{
connection.Open();
using
(SqlCommand command =
new
SqlCommand(sql, connection))
{
command.ExecuteNonQuery();
}
}
}
public
void
Update(ASoratModel model)
{
String sql =
"update [test] set name='"
+model.name+
"',title='"
+model.title+
"' where id="
+model.id;
using
(SqlConnection connection =
new
SqlConnection(sqlCnStr))
{
connection.Open();
using
(SqlCommand command =
new
SqlCommand(sql, connection))
{
command.ExecuteNonQuery();
}
}
}
public
void
Delete(ASoratModel model)
{
}
}
}
public
ActionResult Read([DataSourceRequest] DataSourceRequest request)
{
return
Json(aSoratService.Read().ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Update([DataSourceRequest] DataSourceRequest request,
IEnumerable
<ASoratModel> asorats
){
foreach
(var item
in
asorats)
{
aSoratService.Update(item);
}
return
Json(asorats.ToDataSourceResult(request,ModelState));
}
@
using
webArta.Models
@
using
System.Linq
@
using
System.Data
@(Html.Kendo().Grid<webArta.Models.ASoratModel>()
.Name(
"grid"
)
.Columns(columns =>
{
columns.Bound(p => p.name);
columns.Bound(p => p.title);
//columns.Command(c =>
//{
// c.Edit();
// c.Destroy();
//});
})
.ToolBar(t =>
{
t.Save();
t.Create();
})
.DataSource(dataSource => dataSource
.Ajax()
.AutoSync(
true
)
.Batch(
true
)
.Model(m => m.Id(p => p.id))
.Read(r => r.Action(
"Read"
,
"MY_CONTROLLER"
)
)
.Create(update => update.Action(
"Create"
,
"MY_CONTROLLER"
))
.Update(update => update.Action(
"Update"
,
"MY_CONTROLLER"
))
.Destroy(update => update.Action(
"EditingInline_Destroy"
,
"MY_CONTROLLER"
))
.ServerOperation(
true
)
)
.Navigatable()
.Pageable()
.Sortable()
.Editable(ed =>
{
ed.Mode(GridEditMode.InCell);
ed.CreateAt(GridInsertRowPosition.Bottom);
})
.Scrollable()
.Filterable()
.Resizable(resize => resize.Columns(
true
))
)