I have a Session object. Each Session can be related to many Templates and each template has a list of Items (like an Enum list). Users can define a Template and its List of enums. The fun is that the user needs to filter on these dynamic properties and I'm trying to figure out how to do it. I need your help.
Template 1
- List Item 1
- List Item 2
- List Item 3
In the field list I need the list of Templates... which is dynamic. Right now, I have "Name". I need "Template 1", "Template 2", etc. Then, I need a pick list for each of them based on their own Items. So, select template 1 and filter on List Item 1. Give me all the sessions where Template 1's value is List Item 1. How do I do this in your Filter control.
Also, a side note. There is NO documentation on how to define the Html.Kendo().DataSource object. I don't believe my example works. I actually have the values in the MODEL and would like to just use the given values without needing to perform an Action.
View:
@(Html.Kendo().DataSource<
SessionOptionTemplate
> ()
.Name("templateDataSource")
.Ajax(d => d.Read(
r => r.Action("Templates", "Sessions"))))
@(Html.Kendo().Filter<
SessionOptionTemplate
>()
.Name("filter")
.MainLogic(FilterCompositionLogicalOperator.Or)
.ApplyButton()
.ExpressionPreview()
.Fields(f =>
{
f.Add(p => p.Name).Label("Name");
})
.DataSource("templateDataSource"))
Controller:
public async Task<
IActionResult
> Templates(
[DataSourceRequest] DataSourceRequest request)
{
var dsResult = await profileService.SessionOptionTemplates.ToDataSourceResultAsync(request);
return Json(dsResult);
}
Template:
public partial class SessionOptionTemplate
{
public int Id { get; set; }
[MaxLength(50)]
public string Name { get; set; }
[MaxLength(128)]
public string Description { get; set; }
public int Order { get; set; }
public DateTime AddTimestamp { get; set; } = DateTime.UtcNow;
public DateTime? DeactivateTimestamp { get; set; }
public ICollection<
SessionOptionItem
> SessionOptionItems { get; set; } = new HashSet<
SessionOptionItem
>();
}
Items:
public partial class SessionOptionItem
{
[Key]
public int Id { get; set; }
public int SessionOptionTemplateId { get; set; }
[MaxLength(50)]
public string Name { get; set; }
[MaxLength(128)]
public string Description { get; set; }
public DateTime AddTimestamp { get; set; } = DateTime.UtcNow;
public DateTime? DeactivateTimestamp { get; set; }
}
Dear Admin,
I would like to ask about can FileManager upload with extra parameter?
Regards,
EL
I put a button, call the post method to change data. I want to refresh the grid to show the data. Please help.
Hi to all,
I have this collection routine
contacts = from rec
in
_context.Contacts.Include(
"SellToContacts"
)
where rec.ParentContactFK.HasValue ==
false
select rec;
DataSourceResult result = contacts.ToDataSourceResult(request);
return
Json(result);
Contact model is configured in this mode
[...]
public
Contact ContactParent {
get
;
set
; }
[Column(
"Parent Contact Id"
, TypeName =
"int"
)]
[Display(Name =
"Società Principale"
)]
public
int
? ParentContactFK {
get
;
set
; }
[ForeignKey(
"ParentContactFK"
)]
public
ICollection<Contact> SellToContacts{
get
;
set
; }
[...]
with this collection I would show a column that shows a Count of SellToContacts, that there are children of primary contact.
If a try to debug a collection, I found , correctly, some SellToContacts loaded of several children.
[...]
@(Html.Kendo().Grid<
Portale.Web2.Data.Entities.Contact
>
()
.Name("contactGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetContacts", "Contacts").Data("addInfo"))
)
.Columns(columns =>
{
columns.Bound(c => c.Date).Format("{0:dd/MM/yyyy}");
columns.Bound(c => c.Name);
columns.Bound(c => c.SellToContacts.Count);
[...]
Why not appears into a grid?
Where I wrong?
Hello,
I am using an aspnetcore Grid and I noticed that the style of the edit form is different from the rest of the site.
For information, my site is setup to use the telerik bootstrap 4 style with custom colors (used the Telerik Theme Builder)
The problem I experience seems related to the classes used in my site versus the demo. In the demo (https://demos.telerik.com/aspnet-core/grid/editing-popup), the control classes all use a k- prefix. "k-textbox" "k-input" "k-numerictextbox". On my site, the classes are text-box single-line only. When I manually change them to k-textbox for example, the css applies and is displayed properly.
Did I configure something improperly for the classes used to be different from the demo?
Any help would be appreciated!
Hi Everyone,
I am trying to set the Kendo Grid with Group by specific column by default, so I have used the code snippet as shown below:
@(Html.Kendo().Grid<StudentRecord>().Name("Grid")
.Groupable()
.Sortable()
.GroupPaging(true)
.Group(x => x.Add(y => y.StartYear))
And I realised it always displays the StartYear groups in ascending order by default.
Please advise how I could set the StartYear groups to sort in descending order by default.
Thank you.
I am using the new System.Text.Json in asp.net core and I noticed that the grid does not bind to the model when using the new .net Core Json library. If I use Newtonsoft.Json the bind binding works fine.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddKendo();
services.AddControllersWithViews();
//.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
}
@(Html.Kendo().Grid<TestModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(e => e.email);
columns.Bound(e => e.username);
})
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(100)
.Read(read => read.Action("Read", "home"))
)
)
Model
public class TestModel
{
public string archiveGuid { get; set; }
public string orgUid { get; set; }
public string orgName { get; set; }
public string orgExtRef { get; set; }
public string userUid { get; set; }
public string username { get; set; }
public string email { get; set; }
}
Here is what is returned with NewtonSoft JSON. I also noticed that D in the data response sent is capitalized when using Newtonsoft.json. Any ideas? It could be due to the contract resolver not being set when we are using the System.Text.Json as posted here https://www.telerik.com/forums/grid---binding-doesn't-work but I don't think there is a contract resolver option for the System.Text.Json.
So I have a grid, with a template for the command buttons. The reason I have the template, is I'm not allowing in-line editing, and the "edit" button will take the user to a detail page where they get access to the full model record.
I also have a "delete" button, but I can't figure out how to perform the delete from the template. I tried what I've seen in others and attempt to get the closest "tr" and then call "removerRow", but that did not work.
<
script
type
=
"text/x-kendo-template"
id
=
"Commands"
>
<
form
method
=
"post"
action
=
"@Url.Page("
/clients/client", new {
area
=
""
})"
style
=
"float: left; margin-right: .55rem"
>
<
button
type
=
"submit"
class
=
"btn btn-info waves-effect waves-light"
>Edit</
button
>
<
input
name
=
"companyId"
type
=
"number"
value
=
"#= CompanyId #"
hidden
=
"hidden"
/>
@Html.AntiForgeryToken()
</
form
>
<
button
name
=
"btnDelete"
class
=
"btn btn-danger waves-effect waves-light"
onclick
=
"deleteObject()"
>Delete</
button
>
</
script
>
<
script
>
var commandTemplate = kendo.template($('#Commands').html());
</
script
>
<
script
type
=
"text/javascript"
>
function deleteObject() {
var row = $(this).closest("tr");
$("#clientGrid").data("kendoGrid").removeRow(row);
}
</
script
>
@(Html.Kendo().Grid<
CaterX2.Models.Client.Client
>()
.Name("clientGrid")
.Columns(columns =>
{
columns.Bound(p => p.CompanyName).Title("Client");
columns.Bound(p => p.Address1);
columns.Bound(p => p.Address2);
columns.Bound(p => p.City);
columns.Bound(p => p.State.StateCode).Title("State").Width(100);
columns.Bound(p => p.ZipCode).Title("Zip Code").Width(150);
columns.Bound(p => p.PhoneNumber).Title("Phone").Width(150);
columns.Bound(p => p.CompanyId).ClientTemplate("#=commandTemplate(data)#").Width(200);
})
.Pageable()
.Sortable()
.Scrollable()
.Selectable(s => s.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
.HtmlAttributes(new { style = "height:430px;"})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.CompanyId))
.Read(r => r.Url("/index?handler=Read").Data("forgeryToken"))
.Update(e => e.Url("index?handler=Edit"))
.Destroy(d => d.Url("index?handler=Delete").Data("forgeryToken"))
)
)
I'm trying to define a grid where the first column is a checkbox and the 2nd has a large font bound to "name" with a small font below it showing the "description". I'd appreciate a working example.
This is NOT working:
<
script
id
=
"rowTemplate"
type
=
"text/x-kendo-tmpl"
>
<
tr
data-uid
=
"#: uid #"
>
<
td
class
=
"checkbox"
>
<
input
type
=
"checkbox"
name
=
"optCheck"
/>
</
td
>
<
td
class
=
"details"
>
<
span
class
=
"name"
>#: Name #</
span
>
<
span
class
=
"desc"
>#: Description #</
span
>
</
td
>
</
tr
>
</
script
>
@(Html.Kendo().Grid<
SessionOptionTemplate
>()
.Name("template-grid")
.ClientRowTemplate("rowTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("IndexJson", "SessionOptionTemplates")
.Data("getData"))
))
Style
<
style
>
.checkbox {
width: 75px;
}
.details {
width: 400px;
}
.name {
display: block;
font-size: 1.6em;
}
.desc {
display: block;
padding-top: 1.6em;
font-size: small
}
</
style
>