I am using kendo Grid of kendo of ASP.NET MVC 2016.1.412.
My code where I want to get selected is:
column.Bound(e => e.Username).Title("Username").Groupable(true).ClientTemplate("<a style='cursor:pointer' onclick=EditProductDataObject(Username)>#=Username#</a>");
Here instead of username I want to pass whole row object so I can read and use further the coming data.
I have a very basic grid that I built with the telerik mvc grid scaffolding.
I have a column called "parent" that parent should display a 10 digit number, instead it displays "function (){return o}"
I have tried templating, toString and it shows the same thing. every other column works as expected
@(Html.Kendo().Grid<AccountMove.act_trans_worktable>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.customer_name);
columns.Bound(c => c.reason);
columns.Bound(c => c.parent);
})
.Pageable()
.Navigatable()
.Sortable(sortable =>
{
sortable.SortMode(GridSortMode.SingleColumn);
})
.Filterable()
//.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("act_trans_worktable_Read", "mvcgrid"))
)
)
I have a editable Kendo grid with two datepicker inside, the kendo grid and it's controller are part an MVC Area. When i want to save a row the error is shown saying that the value introduced is not valid, i want the date format as dd/MM/yyyy. Those date fields have a template like this:
@(Html.Kendo().DatePicker()
.Name("date")
.Culture("es-MX")
.Format("{0:dd/MM/yyyy}")
.ParseFormats(new string[] { "dd/MM/yyyy" })
)
also in the columns definition have format and even a js function to get the value as i want
.Columns(columns =>
{
columns.Bound(p => p.InicioVigencia).Format("{0:dd/MM/yyyy}").ClientTemplate("#=getDate(InicioVigencia)#");
columns.Bound(p => p.FinVigencia).Format("{0:dd/MM/yyyy}").ClientTemplate("#=getDate(FinVigencia)#");
}
function getDate(object) {
if (object == null || object == "null" || object == "NULL" || object == "Null")
return "";
return kendo.toString(object, "dd/MM/yyyy");
}
In the global.asax i set this properties in order to have the date format i want.
CultureInfo threadCultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone();
CultureInfo uiCultureInfo = (CultureInfo)CultureInfo.CurrentUICulture.Clone();
threadCultureInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
threadCultureInfo.DateTimeFormat.LongDatePattern = "dd/MM/yyyy hh:mm:ss tt";
uiCultureInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
uiCultureInfo.DateTimeFormat.LongDatePattern = "dd/MM/yyyy hh:mm:ss tt";
Thread.CurrentThread.CurrentCulture = threadCultureInfo;
Thread.CurrentThread.CurrentUICulture = uiCultureInfo;
But the system still showing the error, i have other datepickers defined as js in orther controller just like this
$(function () {
$(".date-picker").kendoDatePicker({
animation: {
close: {
effects: "fadeOut zoom:out",
duration: 300
},
open: {
effects: "fadeIn zoom:in",
duration: 300
}
},
format: "dd/MM/yyyy",
culture: "es-MX"
});
});
And everyting is working fine, so i don't know why it is not working properly. if i change global.asax like this
CultureInfo threadCultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone();
CultureInfo uiCultureInfo = (CultureInfo)CultureInfo.CurrentUICulture.Clone();
threadCultureInfo.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
threadCultureInfo.DateTimeFormat.LongDatePattern = "MM/dd/yyyy hh:mm:ss tt";
uiCultureInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
uiCultureInfo.DateTimeFormat.LongDatePattern = "dd/MM/yyyy hh:mm:ss tt";
Thread.CurrentThread.CurrentCulture = threadCultureInfo;
Thread.CurrentThread.CurrentUICulture = uiCultureInfo;
the grid that use the templates work properly but the view with the js stop working
I have a scenario where I need a way for the user to cancel an insert once they have chose to insert a new row.
The configuration is InCell editing with a custom "save" button and a custom "add" on top of the view. So the grid is in batch edit mode and is working fine other than when the user decides to insert a row. If I place a default "Cancel" command that cancel button will be in every row. That is one problem.
So I decided to have a hidden column at the end of the grid with a client template containing a "Cancel" button.
When they insert a new row I hook the onEdit event of the grid and make the column visible. But in doing so all of the column widths get whacked out. I searched a bit to find a resize row method but it is not working.
function
resizeColumnDefaults() {
debugger;
resize(0, 250);
resize(2, 100);
resize(3, 100);
resize(5, 100);
resize(6, 100);
resize(8, 120);
resize(9, 300);
resize(10, 75);
resize(11, 75);
resize(13, 75);
}
function
resize(idx, width) {
$(
"#Grid .k-grid-header-wrap"
)
//header
.find(
"colgroup col"
)
.eq(idx)
.css({ width: width });
$(
"#Grid .k-grid-content"
)
//content
.find(
"colgroup col"
)
.eq(idx)
.css({ width: width });
}
function
onEdit(e) {
var
grid = $(
"#Grid"
).data(
"kendoGrid"
);
grid.showColumn(11);
resizeColumnDefaults();
}
Can someone offer a solution?
Thanks,
Reid
Hi,
Whe I hide columns in a sub-grid I get problems with the look of the sub-grid. The reason seems to be that I hide the last column that does not have the width set (to make this column take up the remaining space in the row).
The template for the sub-grid from the cshtml page:
<script id="utförseltemplate" type="text/x-kendo-tmpl">
@(Html.Kendo().Grid<UtförselViewModel>()
.Name("grid_#=Id#")
.TableHtmlAttributes(new { @class = "ansokan-produkter-utforsel-subgrid" })
.Columns(columns =>
{
columns.Bound(p => p.Id).Hidden(true);
columns.Bound(p => p.UtförselDiarieNummer).Title("Diarienummer").Width(150);
columns.Bound(p => p.Datum).Format("{0:yyyy-MM-dd}").Title("Utförseldatum").Width(120);
columns.Bound(p => p.DelKvantitet).Title("Levererad kvantitet").Width(120);
columns.Bound(p => p.Enhet).Title("Enhet");
})
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(r => r.Action("ProduktUtförslarRead", "Giltiga", new { produktId = "#=ProduktId#", ansökanProduktId = "#=Id#" }))
.Sort(sort => sort.Add(r => r.Datum).Descending())
)
.Events(events => events.DataBound("UtforslarDataBound"))
.ToClientTemplate()
)
</script>
Part of the javscript ondatabound:
if (some condition) {
this.hideColumn(3);
this.hideColumn(4);
}
When I hide this column the grid looks chopped off. I guess that I
need to set the column width in the javascript, but I have not been able
to figure out how.
Can you help me set the column width in the javascript or set the width of the whole sub-grid?
Best regards,
Henrik
I'm setting the value of a property using the following JavaScript code
var
documentList = $(
"#documentsList"
).data(
"kendoListView"
);
var
dataSource = documentList.dataSource;
var
dataUid = documentList.select().attr(
"data-uid"
);
var
item = dataSource.getByUid(dataUid);
var
datepicker = $(
"#documentDate"
).data(
"kendoDatePicker"
);
item.set(
"DocumentDate"
, datepicker.value());
if
(dataSource.hasChanges()) {
dataSource.sync();
}
My controller is receiving the post when the datasource is synced and the other properties are being set. This is the C# of my controller
public
JsonResult Update([DataSourceRequest]DataSourceRequest request, InboxDocument document)
{
return
Json(
new
[] {SharePointHelper.UpdateInboxDocument(HttpContext, document)}.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
All the other properties that are set are being sent through, but when I look at the request sent through in F12 tools, the following is displayed.
{DocumentDate: {errors: ["The value '6/21/2016 1:00:00 AM' is not valid for DocumentDate."]},…}
This is the same for any other date values.
I have two checkboxes in a Kendo MVC Grid row and need some understanding as to how to set the dataitem property when they are clicked. I have been successful when there is one checkbox per row doing the following:
columns.Bound(p => p.bDelete).ClientTemplate("<
input
type
=
'checkbox'
name
=
'bDelete'
Id
=
'bDelete'
#= bDelete ?
checked
=
'checked'
: '' #
class
=
'chkbx'
/>")
.Width(70).HtmlAttributes(new { style = "text-align: center", title = "Delete Selected" });
<script>
// Any rows that get checked or unchecked after the form is loaded need
// to pass though this event to get the underlying record reconciled
$(
function
() {
$(
'#Grid'
)
.on(
'click'
,
'.chkbx'
,
function
(e) {
debugger;
var
checked = $(
this
).is(
':checked'
);
var
grid = $(
'#Grid'
).data().kendoGrid;
var
dataItem = grid.dataItem($(
this
).closest(
'tr'
));
// if we are in insert mode do not let the user check the delete checkbox
if
(dataItem.iProjectSequence == 0) {
e.preventDefault();
dataItem.set(
'bDelete'
,
false
);
return
;
}
dataItem.set(
'bDelete'
, checked);
dataItem.set(
'bModified'
,
true
);
dataItem.set(
'dirty'
,
true
);
SetRowsModifiedState();
SetPageMessage(
"Data Modified"
);
$(
"#New"
).prop(
"disabled"
,
true
);
$(
"#Cancel"
).prop(
"disabled"
,
false
);
});
})
</script>
The code above works for a row that has only one checkbox in it. How do I detect the underlying model value attached to the checkbox being clicked so that I can set *ONLY* that field?
Thanks
I have the following in a template <script type="text/x-kendo-tmpl" id="documentDetailsTemplate"></script>
@(Html.Kendo().MultiSelect()
.Name("otherParties")
.DataSource(ds =>
{
ds.Read("GetOtherParties", "Term", new { SPHostUrl = ViewBag.SPHostUrl });
})
.DataValueField("TermId")
.DataTextField("Label")
.AutoBind(false)
.HtmlAttributes(new { style = "width:100%" })
.Placeholder("Select Other Parties...")
.ItemTemplate("<
div
class=\"k-state-default term-label\">\\#= data.Label \\#</
div
><
div
class=\"k-state-default term-path\">\\#= data.Path \\#</
div
>")
.Value("#: OtherParties #")
.MinLength(3)
.Filter(FilterType.Contains)
.ToClientTemplate())
The OtherParties property is a List of classes as detailed in the code snippet below.
public
class
TermItem
{
public
Guid TermId {
get
;
set
; }
public
string
Label {
get
;
set
; }
public
string
Path {
get
;
set
; }
}
public
List<TermItem> OtherParties {
get
;
set
; }
The template is then passed with a dataItem in javascript using the code below.
var
documentList = $(
"#documentsList"
).data(
"kendoListView"
);
var
dataSource = documentList.dataSource;
var
document = dataSource.getByUid(documentList.select().attr(
"data-uid"
));
var
template = kendo.template($(
"#documentDetailsTemplate"
).html());
Have checked with Fiddler and the values are coming back correctly. Have debugged the JavaScript and the document object in the snippet above has the values in it.
The documentation at http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/multiselect/overview#pre-select-values-on-initial-load says that you need to select it with a List<class> object.
It's not pre-selecting the values when the template is generated.
Any ideas on what is the correct way to do this?
Hello,
I have one field in Connection model that user should be able to change - "MyConnectionField" in example below.
The thing is that this field can contain different types of data depending on other field in the model. When user clicks on connection in diagram and chooses Edit, dialog pops up with the editable field with label "MyConnectionField". How can I change this label depending on other field in the Connection model - "MyTypeField" in example below?
@(Html.Kendo().Diagram<Shape, Connection>()
...
.ConnectionsDataSource(d => d
.Model(m =>
{
m.Id(c => c.Id); m.Field(c => c.MyTypeField);
m.Field(c => c.MyConnectionField).Editable(
true
);
})
.Read(r =>
{
r.Action(
"MyAction"
,
"MyController"
);
})
)
.ConnectionDefaults(cd => cd
.Editable(e => e.Drag(false).Remove(false)
.Tools(t => {
t.Edit();
})
)
)
...
)