I am returning errors from server and catch it in kendo datasource error event.In this event I am trying to prevent close popup editor, but it works only first time, after clicking update second time, the window closes.
I searched a lot but could not find a solution
City = {
InitializeGrid: function () {
function LoadCities(url, success) {
Common.serverRequest(url, success);
}
function UpdateCity(url, params, success) {
Common.serverRequestParams(url, params, success);
}
function InsertCity(url, params, success) {
Common.serverRequestParams(url, params, success);
}
function DeleteCity(url, id, success) {
Common.serverRequestParams(url, id, success);
}
dataSource = new kendo.data.DataSource({
transport: {
read: function (e) {
LoadCities("/home/read", function (res) {
e.success(res);
});
},
update: function (e) {
UpdateCity("/home/update", e.data, function (res) {
var grid = $("#grid").data("kendoGrid");
if (res.success) {
grid.dataSource.read();
} else {
e.error("", "", res.error);
grid.cancelChanges();
}
});
},
create: function (e) {
InsertCity("/home/insert", e.data, function (res) {
var grid = $("#grid").data("kendoGrid");
if (res.success) {
grid.dataSource.data(res.data);
} else {
e.error("", "", res.error);
grid.cancelChanges();
}
});
},
destroy: function (e) {
DeleteCity("/home/delete", e.data, function (res) {
var grid = $("#grid").data("kendoGrid");
if (res.success) {
grid.dataSource.data(res.data);
} else {
e.error("", "", res.error);
grid.cancelChanges();
}
});
}
},
error: function (e) {
var grid = $("#grid").data("kendoGrid");
grid.one("dataBinding", function (e) {
e.preventDefault(); // it occures only first time
});
alert(e.errorThrown);
},
pageSize: 20,
schema: {
model: {
id: "Id",
fields: {
Name: { type: "string" },
EndDate: { type: "date" },
CreateDate: { type: "date" }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
height: 750,
selectable: "single",
filterable: true,
sortable: true,
pageable: true,
toolbar: [{ name: "newRecord", text: "New Record" }, { name: "editRecord", text: "Edit REcord" }, { name: "deleteRecord", text: "Delete" }],
columns: [
{ field: "Name", title: "Name" },
{ field: "EndDate", title: "End Date", format: "{0:dd.MM.yyyy hh:mm}" },
{ field: "CreateDate", title: "Create Date", format: "{0:dd.MM.yyyy hh:mm}" }
],
editable: {
mode: "popup",
confirmation: false,
template: kendo.template($("#popup_editor").html())
}
});
$("#grid").on("click", ".k-grid-newRecord", function () {
Common.gridAdd('grid', 'New Record');
});
$("#grid").on("click", ".k-grid-editRecord", function () {
Common.gridEdit('grid', 'Edit Record');
});
$("#grid").on("click", ".k-grid-deleteRecord", function () {
Common.gridDelete('grid');
});
}
}
mvc controler
public class HomeController : Controller
{
List<
City
> cities;
public string error { get; set; }
public bool isSuccess { get; set; } = true;
public ActionResult Index()
{
cities = new List<
City
>();
Session["city"] = cities;
return View();
}
public ActionResult Read()
{
var result = (List<
City
>)Session["city"];
return Json(result);
}
public ActionResult Update(City item)
{
var result = (List<
City
>)Session["city"];
if (string.IsNullOrEmpty(item.Name))
{
error = "Name is required";
isSuccess = false;
}
result.Where(w => w.Id == item.Id).SingleOrDefault(s => s == item);
return Json(new { success = isSuccess, error =error, data = item });
}
public ActionResult Insert(City item)
{
var result = (List<
City
>)Session["city"];
item.Id = result.Count;
item.Id++;
if (string.IsNullOrEmpty(item.Name))
{
error = "Name is required";
isSuccess = false;
}
result.Add(item);
return Json(new { success = isSuccess, error = error, data = item });
}
public ActionResult Delete(City item)
{
var result = (List<
City
>)Session["city"];
result.Remove(item);
return Json(new { success = isSuccess });
}
}
Hi there,
How do you customise the image on the loading spinner for a Kendo Grid? I have an animated gif called 'loading.gif' that I wish to use instead of the default image currently.
Thanks, Mark
Hello,
I'm trying to implement kendo ui Scheduler .
But I realised that when I have many events in the same day I could see only two events and the others are collapsed on "three points".
When I click on the point it redirect me to Day view to see all the planned events.
I really want to remove the Day view and show only Month and Agenda Views.
It is possible to modify the code so when I click on the "three points" it redirect me to the Agenda view or could the Month view be resized dynamically depending on the number of the events ?
I tried to modify the CSS of the schudeler , but I didn't like the result
<
style
>
.k-scheduler-table td, .k-scheduler-table th
{
height: 15.5em;
}
.k-scheduler-monthview .k-scheduler-table td
{
height: 15.5em;
}
.k-scheduler-timecolumn{
visibility:collapse !important;
width:0 !important;
}
.k-more-events > span {
margin-top: 0em;
height: 20px;
}
div.k-more-events {
font-size: 12px;
height: 20px;
}
.k-scheduler-table td, .k-scheduler-table th {
height: 1em;
padding: .334em .5em;
font-size: 100%;
}
</
style
>
Thank you in advance,
Best.
The following code to generate some rectangles with text items (see attached). What do I need to do to center each text item in its rectangle? I see there's a Layout, but I'm not sure how to combine rectangles, paths and groups into on of those.
var vLines = [5, 90, 175, 260, 345, 430, 515, 600];
...
$.each(vLines, function (index, value) {
var group = getBox("line " + count++, "line " + count++, "line " + count++);
group.transform(geom.transform().translate(10, value));
surface.draw(group);
});
....
function getBox(text1, text2, text3) {
var lineColor = "#9999b6";
var lineWidth = 2;
var fontNormal = "12px Arial";
var group = new draw.Group();
var rect = new geom.Rect([0, 0], [160, 75]);
var path = draw.Path.fromRect(rect, { stroke: { color: lineColor, width: lineWidth } });
group.append(path);
if (text1) {
group.append(new draw.Text(text1, new geom.Point(10, 10), { font: fontNormal }));
}
if (text2) {
group.append(new draw.Text(text2, new geom.Point(10, 30), { font: fontNormal }));
}
if (text3) {
group.append(new draw.Text(text3, new geom.Point(10, 50), { font: fontNormal }));
}
return group;
}
Thanks
Hi, in our app, customers can create "custom Fields", and they can have any title they want.
Ideally, we always prefer to keep original values in javascript objects without encoding them, and use templates to encode if needed.
I have this very "limit" case, where the title of a columns is "<script>alert(1)</script>".
https://dojo.telerik.com/@foxontherock/imacAYOR/3
There are 3 cases, one with script, one with bold, both with templating, and the last one, bold without template (all default)
I am able to use a groupTemplate and headerTemplate to display them correctly.
But, I tried several methods to make the "columnMenu" appear correctly, I never found a solution.
I tried the "columnMenuInit", but the "alert" appear before the init event.
What I can do for now is set "menu=false" for these columns...
I don't want to "htmlEncode" the title property itself.
Is it possible to set a custom template on the kendoMenu that is displayed to choose the column, or is it possible to set a setting to let the menu encode the text?
For exemple, I can set a title like <b>mytext</b> and the text will appear as bold in the menu!
I think that you forgot to encode the title when the columnmenu is displayed.
The "encode" parameter correctly encode the value, but doesn't affect the title.
Maybe we should get a encodeTitle attribute?
I think that all of this should work correctly without any custom templates.
<note>
You can't say that you don't support it,
because, you did it correctly in the "drop zone" when grouping,
the title is htmlencoded without any need for custom template!!!
just try it with the "bold no template" column and you'll see.
</note>
var
gridDataSource =
new
kendo.data.DataSource({
data: results,
total: results.length,
pageSize: 20,
schema: {
model: {
id:
"id"
,
fields: {
attributes: { type:
"object"
}
}
}
}
});
//Build the Kendo UI grid
var
kendoDataGrid = $(
"#dataGrid"
).kendoGrid({
dataSource: gridDataSource,
columns: GetGridColumns(),
scrollable:
true
,
pageable:
true
,
resizable:
true
,
sortable:
true
,
selectable:
"row"
,
navigatable:
true
,
height: gridHeight,
editable:
false
}).data(
"kendoGrid"
);
Couldn't find any similar questions on the forum so hopefully someone can help :)
At the moment I have a pre-filter on my grid, which filters a column based on the role of the logged in user.
filter: {
filters: [{ field: "RSM", operator: "contains", value: manager}]
}
This pre-filters the grid when the logged in user is a manager. The issue I'm having is it will always pre-filter the grid even if the logged in user isn't a manager. So although the data itself won't be filtered, it will still appear as if the Manager column is being filtered.
https://ibb.co/FX3c6Qb
So is it possible to only apply the filter if the current user is a manager only? If it's just a regular user then don't apply the filter.
Thanks as always.
@
using
Kendo.Mvc.UI.Fluent
@model PosPayAndBankRec.Models.TreasuryCreateModel
@functions {
private
void
AccountGridCommandDef(GridColumnFactory<PosPayAndBankRec.Models.TreasuryCreateItem> columns)
{
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
columns.Bound(p => p.AccountID).Hidden();
columns.Bound(p => p.BankID).Hidden();
columns.Bound(p => p.BankName).Title(
"Bank"
).Width(120);
columns.Bound(p => p.RamQuestBankNumber).Title(
"Bank #"
).Width(60);
columns.Bound(p => p.AccountName).Title(
"Account"
).Title(
"Location"
);
columns.Bound(p => p.AccountNumber).Title(
"Acct #"
);
columns.Bound(p => p.PpStatus).Title(
"Positive Pay"
);
columns.Bound(p => p.BrStatus).Title(
"Bank Rec"
);
//columns.Bound(p => p.AccountFolderName).Title("Folder");
}
private
void
AccountGridDataSource(DataSourceBuilder<PosPayAndBankRec.Models.TreasuryCreateItem> dataSource)
{
dataSource.Ajax()
.Model(AjaxAccountDataSourceBuilder)
.Sort(sort => sort.Add(p => p.BankName))
.ServerOperation(
true
)
.Create(create => create.Action(
"Create"
,
"Home"
))
.Read(read => read.Action(
"Read"
,
"Home"
,
new
{ id = Request.QueryString[
"id"
] }))
.Update(update => update.Action(
"Edit"
,
"Home"
))
.Destroy(destroy => destroy.Action(
"Delete"
,
"Home"
));
//.Events(e => e.Error("error"));
}
private
void
AjaxAccountDataSourceBuilder(DataSourceModelDescriptorFactory<PosPayAndBankRec.Models.TreasuryCreateItem> model)
{
model.Id(p => p.AccountID);
model.Field(p => p.AccountName);
}
private
void
AccountGridToolBarDef(GridToolBarCommandFactory<PosPayAndBankRec.Models.TreasuryCreateItem> toolbar)
{
toolbar.Create().Text(
"Treasury Request"
);
}
}
@{ ViewBag.Title =
"Treasury Connections"
; }
@(Html.Kendo().Grid<PosPayAndBankRec.Models.TreasuryCreateItem>()
.Name(
"Treasuries"
)
.Columns(AccountGridCommandDef)
.DataSource(AccountGridDataSource)
.ToolBar(AccountGridToolBarDef)
.Editable(c => c.Mode(GridEditMode.PopUp).Enabled(
true
).DisplayDeleteConfirmation(
true
).Window(window => window.Title(
"Treasury Request"
)).TemplateName(
"TreasuryPopup"
).AdditionalViewData(
new
{ Banks = Model.Banks }))
.Sortable()
.Filterable()
.Resizable(resize => resize.Columns(
true
))
.Reorderable(reorder => reorder.Columns(
true
))
.ClientDetailTemplateId(
"ContactDetails"
)
.Pageable(p => p.Enabled(
false
))
.Scrollable(s => { s.Height(700); s.Virtual(
true
); })
)
</script>
<script id=
"ContactDetails"
type=
"text/kendo-tmpl"
>
@(Html.Kendo().Grid<PosPayAndBankRec.Models.ContactDetailsModel>()
.Name(
"Details_#=BankID#"
)
.Columns(columns =>
{
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
columns.Bound(p => p.ContactName).Width(150);
columns.Bound(p => p.ContactType).Width(100);
//columns.Bound(p => p.ContactEmail).Width(150);
columns.Bound(p => p.ContactPhone).Width(100);
columns.Bound(p => p.Description).Width(100);
//columns.Bound(p => p.ContactNotes).Width(200);
})
.ToolBar(p => p.Create())
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.BankID))
.Sort(sort => sort.Add(p => p.ContactName))
.ServerOperation(
true
)
.Create(create => create.Action(
"Create"
,
"Contact"
))
.Read(read => read.Action(
"Details"
,
"Contact"
,
new
{ id =
"#=BankID#"
}))
.Update(update => update.Action(
"Update"
,
"Contact"
))
.Destroy(destroy => destroy.Action(
"Delete"
,
"Contact"
))
)
.Pageable()
.Sortable()
.Resizable(resize => resize.Columns(
true
))
.Reorderable(reorder => reorder.Columns(
true
))
.Editable(c => c.Mode(GridEditMode.PopUp).Enabled(
true
).DisplayDeleteConfirmation(
true
).Window(window => window.Title(
"Contact"
)).TemplateName(
"ContactPopup"
).AdditionalViewData(
new
{ Banks = Model.Banks }))
.ToClientTemplate())
.ToClientTemplate())
</script>
@
using
System.Collections
@
using
PosPayAndBankRec.Models
@model PosPayAndBankRec.Models.TreasuryCreateItem
@{
ViewBag.Title =
"Treasury"
;
}
<fieldset>
<legend>Bank Account Info</legend>
<table id=
"table"
>
<tr>
<th>
Bank
</th>
<td>
@(Html.Kendo().DropDownListFor(model => model.BankID)
.Name(
"BankID"
)
.OptionLabel(
"-- Select Item --"
)
.DataTextField(
"BankName"
)
.DataValueField(
"BankID"
)
.DataSource(source => {
source.Read(read =>
{
read.Action(
"GetCascadeBanks"
,
"Home"
);
});
})
)
</td>
</tr>
<tr>
<th>
Location
</th>
<td colspan=
"2"
>
<script type=
"text/javascript"
>
// function ShowHide(chk,txt)
// {
// if ((document.getElementById(chk).checked))
// document.getElementById(txt).style.display='';
// else
// document.getElementById(txt).style.display='none';
// }
$(document).ready(function () {
$(
"#AccountID"
).trigger(
"valueChange"
);
});
</script>
@(Html.Kendo().DropDownListFor(model => model.AccountID)
.Name(
"AccountID"
)
.OptionLabel(
"-- Select Item --"
)
.DataTextField(
"AccountName"
)
.DataValueField(
"AccountID"
)
.DataSource(source => {
source.Read(read =>
{
read.Action(
"GetCascadeAccounts"
,
"Home"
)
.Data(
"getBankID"
);
})
.ServerFiltering(
true
);
})
.Enable(
false
)
.AutoBind(
false
)
.CascadeFrom(
"BankID"
)
.Events(events => events.Change(
"onBankChange"
)
)
)
</td>
</tr>
<tr>
<td>
</td>
<th>
Active
</th>
<th>
Deactive
</th>
</tr>
<tr>
<th>
Bank Reconcilliation
</th>
<td>
@Html.EditorFor(model => model.BrActivationDate)
</td>
<td>
@Html.EditorFor(model => model.BrDeactivationDate)
</td>
</tr>
<tr>
<th>
Positive Pay
</th>
<td>
@Html.EditorFor(model => model.PpActivationDate)
</td>
<td>
@Html.EditorFor(model => model.PpDeactivationDate)
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Contacts</legend>
@(Html.Kendo().Grid<PosPayAndBankRec.Models.ContactDetailsModel>()
.Name(
"Contacts"
)
.Columns(columns =>
{
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
columns.Bound(p => p.ContactName).Width(150);
columns.Bound(p => p.ContactType).Width(100);
//columns.Bound(p => p.ContactEmail).Width(150);
columns.Bound(p => p.ContactPhone).Width(100);
//columns.Bound(p => p.Description).Width(100);
//columns.Bound(p => p.ContactNotes).Width(200);
})
.ToolBar(p => p.Create())
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.BankID))
.Sort(sort => sort.Add(p => p.ContactName))
.ServerOperation(
true
)
.Create(create => create.Action(
"Create"
,
"Contact"
))
.Read(read => read.Action(
"GetCascadeContacts"
,
"Home"
)
.Data(
"getBankID"
))
.Update(update => update.Action(
"Edit"
,
"Contact"
))
.Destroy(destroy => destroy.Action(
"Delete"
,
"Contact"
))
)
//.AutoBind(false)
.Pageable()
.Sortable()
.Resizable(resize => resize.Columns(
true
))
.Reorderable(reorder => reorder.Columns(
true
))
.Editable(c => c.Mode(GridEditMode.PopUp).Enabled(
true
).DisplayDeleteConfirmation(
true
).Window(window => window.Title(
"Contact"
)).TemplateName(
"ContactPopup"
)))
</fieldset>
public
ActionResult GetCascadeContacts([DataSourceRequest] DataSourceRequest request,
int
BankID)
{
var ortcontacts = from contact
in
db.ORTContacts
join bank
in
db.ORTBanks on contact.BankID equals bank.BankID
where contact.BankID == BankID
orderby contact.ContactName
select
new
TreasuryCreateItem()
{
ContactID = contact.ContactID,
ContactName = contact.ContactName,
ContactEmail = contact.ContactEmail,
ContactPhone = contact.ContactPhone,
ContactType = contact.ContactType,
ContactNotes = contact.ContactNotes,
BankID = contact.BankID,
BankName = bank.BankName
};
return
Json(ortcontacts.ToDataSourceResult(request));
}
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
PosPayAndBankRec.Domain.Models;
using
System.ComponentModel.DataAnnotations;
using
PosPayAndBankRec.Models.Validators;
namespace
PosPayAndBankRec.Models
{
public
class
TreasuryCreateItem
{
public
int
AccountID {
get
;
set
; }
public
int
BankID {
get
;
set
; }
public
string
BankName {
get
;
set
; }
[Required]
[UniqueAccountName(
"This bank is already named in the system."
)]
[DataType(DataType.Text)]
public
string
BankAccountName {
get
;
set
; }
[Required]
[UniqueAccountName(
"This account is already named in the system."
)]
[DataType(DataType.Text)]
public
string
AccountName {
get
;
set
; }
public
string
AccountNumber {
get
;
set
; }
public
string
RamQuestBankNumber {
get
;
set
; }
public
string
ContactType {
get
;
set
; }
public
string
Description {
get
;
set
; }
public
int
ContactID {
get
;
set
; }
public
string
ContactName {
get
;
set
; }
public
string
ContactPhone {
get
;
set
; }
public
string
ContactEmail {
get
;
set
; }
public
string
ContactNotes {
get
;
set
; }
public
bool
? HasPosPay {
get
;
set
; }
public
bool
? HasBankRec {
get
;
set
; }
public
string
BrStatus {
get
;
set
; }
public
string
PpStatus {
get
;
set
; }
public
string
BrStatusNotes {
get
;
set
; }
public
string
PpStatusNotes {
get
;
set
; }
public
Nullable<System.DateTime> BrActivationDate {
get
;
set
; }
public
Nullable<System.DateTime> BrDeactivationDate {
get
;
set
; }
public
Nullable<System.DateTime> PpActivationDate {
get
;
set
; }
public
Nullable<System.DateTime> PpDeactivationDate {
get
;
set
; }
public
List<ORTBank> Banks {
get
;
set
; }
}
public
class
TreasuryCreateModel
{
public
List<ORTBank> Banks {
get
;
set
; }
public
List<ORTAccount> Accounts {
get
;
set
; }
public
List<ORTContact> Contacts {
get
;
set
; }
public
IEnumerable<TreasuryCreateItem> TreasuryCreateItems {
get
;
set
; }
}
}
<script type=
"text/javascript"
>
function
onBankChange(e) {
var
BankID;
var
bankDropdown =
this
;
var
contactGrid = $(
"#Contacts"
).data(
"kendoGrid"
);
// Set BankId to the selected id of the bankDropDown
BankID = $.map(
this
.select(),
function
(item) {
var
dataItem = bankDropdown.dataItem(bankDropdown.select()).Id;
});
// Read the datasource again
contactGrid.dataSource.read();
}
function
getBankID() {
return
{
BankID: $(
"#BankID"
).val()
};
}
function
setPopupDimensions(ev) {
window.setTimeout(
function
() {
$(
".k-edit-form-container"
).parent().width(800).height(400).data(
"kendoWindow"
).center();
}, 100);
}
</script>
Is there an example of how to render a bar code widget in a pdf export header using a kendo template? I'm using MVC/Razor.
This does not work
<script type="x/kendo-template" id="page-template">
<div class="pdf-page-template">
<div class="header">
<h1>My Order</h1>
<div>@(Html.Kendo().Barcode().Name("gudbrands").Value(Model.OrderNumber).Encoding(BarcodeSymbology.Code39).Width(280).Height(100))</div>
<div><strong>Order Number</strong> @Model.Header.OrderNumber
</div>
</div>
</script>
Hello,
Our app displays many numbers and we often use the kendo.toString function according to https://docs.telerik.com/kendo-ui/globalization/intl/numberformatting
In some places we use it with the format ##,# (to display integers) and in others we use ##,#.00 to always print the decimal part.
Here are two examples:
kendo.toString(12345.10, "##,#”) >>”12,345"
kendo.toString(12345.10, "##,#.00”) >> "12,345.10"
In certain area we wish to be able and present integers as integers, and without the decimal part, and present floats with two decimal parts.
Clearly we cannot use any of the suggested format. Using ##,# only gives integers and ##,#.00 will turn 10 into 10.00 while we wish to keep it as 10
We also cannot use ##,#.## because we cannot allow only 1 decimal digit. The result of kendo.toString(10.1, "##,#.##”) is “10.1” but we must have it as “10.10” because we need either 0 decimal figures or 2.
Is there a format that can answer this need?
Thanks,
Ron.