#(Html.Kendo().Grid<...>()
.Columns(columns =>
{
columns.Bound(j => j.Type);
columns.Bound(j => j.Code);
})
.Sortable(s => s.Enabled(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Sort(p => { p.Add("Code").Ascending(); p.Add("Type").Ascending(); })
.Model(model => model.Id(j => j.ID))
.Read(...)
.ServerOperation(true)
)
)
I have a Kendo MVC Grid as above and want to sort it first by type, then by code.
I have found such implementation on official Telerik forum: Default Grid Sorting
However it seems it fails to work...
The records are sorted by two columns, and apparently it is sorted by Type, but it fails to sort by Code afterwards...As Default should after CG...
What am I missing and how can I fix the problem?
For anyone else looking for a solution, using the model property names worked for me, i.e.
.Sort(s =>
{
s.Add("Code").Ascending();
s.Add("Type").Ascending();
})
Try this way
.Sort(p=> {p.Add(s=>s.Code).Ascending(); p.Add(s=>s.Type).Ascending();})
Related
Getting below error while binding Kendo MVC Grid for select box.
(44): error CS1501: No overload for method 'Select' takes 0 arguments
Below is the my code:
#{Html.Kendo().Grid(Model)
.Name("EmpGrid")
.Pageable()
.Filterable()
.DataSource(d => d
.Server()
.Model(model => model.Id(p => p.empId))
.PageSize(25)
)
.Columns(columns =>
{
columns.Select();
columns.Bound(r => r.Name).Width(160);
}).Render();
}
Please suggest me where I am doing wrong.
If I removes "columns.Select();" from columns it's working.
Thanks.
I think due to Kendo old version it's not binding. Accomplished it by using template option like below.
columns.Template(#<text><input type="checkbox"/></text>).HeaderTemplate(#<text><input type="checkbox" /></text>); columns.Template(#<text><input type="checkbox"/></text>).HeaderTemplate(#<text><input type="checkbox" /></text>);
Thanks
I have a page that has a Kendo grid on it.
It is calling an ajaz web request to get its data.
Once the data has been returned it is grouped in the frontend.
The problem I am having is sorting the groups. What is the best way to do this?
My MVC view code looks something like this...
.DataSource(dataSource => dataSource
.Ajax()
.Group(groups =>
{
groups.Add(c => c.groupingField);
})
.Read(...))
I have tried to use the sort method but am not sure where to put it when the data is coming from an ajax call.
I found that adding the below line to the datasource call solved my problem...
.Sort(sort => sort.Add("FIELD_NAME").Ascending())
You need to provide groups in correct order in .Group() method. I don't have mvc version installed but for example it should be ok:
var groupList = new List<string> { "Gr1", "Gr2" };
.DataSource(dataSource => dataSource
.Ajax()
.Group(groups =>
{
groupList.Select(x => groups.Add(x));
})
.Read(...))
I am trying to embed a chart in a Kendo Grid Cell, following this example: http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-do-i-use-a-kendo-ui-widget-inside-a-grid-client-column-template
I have managed to embed the graph in the grid, but I am unable to find a way to bind to row data.
The ViewModel has properties for each bar value - but how do I bind to those properties (maybe some #= ... # expression?).
I expect something similar to this:
#(Html.Kendo().Grid<ViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.DataID).Filterable(false);
columns.Template(#<text></text>).ClientTemplate(
Html.Kendo().Chart()
.Name("chart#=DataID#")
.Series(series =>
{
series.Bar("\\#= FirstBarValue \\#");
series.Bar("\\#= SecondBarValue \\#");
})
.ToClientTemplate().ToHtmlString()
);
})
.DataSource(dataSource => dataSource.Ajax().PageSize(20).Read(read => read.Action("Read", "Grid"))))
But the FirstBarValue and SecondBarValue are not properly evaluated, although DataID is. Maybe a different scope? I can only make it work with hard coded values.
Any suggestions?
I recently migrated a web application from Telerik Mvc to Kendo UI,
but I'm running into a snag that I'm not too sure how to modify since
I've been learning more about and getting used to Kendo UI the past week.
Here is the problem I'm running into. The error states:
The call is ambiguous between the following methods or
properties: 'System.Linq.Enumerable.Where<Model_OpenAccess_AssetMgr.Custody>
(System.Collections.Generic.IEnumerable<Model_OpenAccess_AssetMgr.Custody>,
System.Func<Model_OpenAccess_AssetMgr.Custody,bool>)'
and 'System.Linq.Enumerable.Where<Model_OpenAccess_AssetMgr.Custody>
(System.Collections.Generic.IEnumerable<Model_OpenAccess_AssetMgr.Custody>,
System.Func<Model_OpenAccess_AssetMgr.Custody,bool>)'
And the code where the error is occurring is below:
#model List<Model_OpenAccess_AssetMgr.Custody>
<div id="AssetDescription" class="detailContainer detailContainer3">
<header class="sectionheader" > Custodians </header>
#(Html.Kendo().Grid(Model.Where(x=>x.Active==true))
.Name("grd_Admin_Custodians")
.HtmlAttributes(new { #class = "ItemsGrid" })
.ToolBar(commands => commands.Create())
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(o => o.Custody_PK))
)
.DataSource(dataSource => dataSource
.Server()
.Read(read => read.Action("AdminHome", "Admin", new { view ="Custodies" }))
.Create("Create", "Admin", new { id = 0, view = "Custodies" })
.Update("Save", "Admin", new { view = "Custodies" })
.Destroy("Delete", "Admin", new { view = "Custodies" }))
.Columns(columns =>
{
columns.Bound(o => o.Custody_Name).Width(200);
columns.Bound(o => o.Custody_Dept).Width(150);
columns.Bound(o => o.Custody_eraider).Width(130);
columns.Bound(o => o.Custody_Type).Width(130);
columns.Bound(o => o.Custody_Email).Width(220);
{
commands.Edit();
commands.Destroy();
}).Width(210);
}
)
.Scrollable(scrolling => scrolling.Enabled(true)}
.Scrollable(scrolling => scrolling.Height(550))
.Pageable()
.Sortable()
)
</div>
)
(Model.Where(x=>x.Active==true) is what is being flagged.
Now, I also have a warning listed at the top underneath
#model List that states:
ASP.NET runtime error: Method not found 'Void
System.Web.Razor.RazorEngineHost.set_EnableInstrumentation(Boolean)'
Which I'm quite certain is interconnected with the error I'm getting.
Do I need to modify the Model.Where() statement somehow?
What do you think I should use instead for Kendo UI?
On another note I recently upgraded this web application project from MVC3 to MVC4
so I don't know if that has anything to do with this or not. But I wanted to go ahead
and let you know of that fact as well.
I've looked at other responses but it appears no one has asked about this for Kendo UI specifically.
Thanks!
It looks to me like you are mixing Server side rendering and Ajax rendering. If using Server side rendering of your grid, you should perform the Where(x=>x.Active==true) filtering in your Model (preferably) or in the Controller Action (less ideal) that uses this view. Not in the view.
If using an Ajax to get the data, say for a paged grid, your datasource needs a read method like
.Read(read => read.Action("Custodians", "Admin"))
I have a kendo UI grid which is similar to this
#(Html.Kendo().Grid<MyViewModel>()
.Name("MyGrid")
.Columns(columns =>
{
columns.Bound(a => a.column1);
columns.Bound(a => a.column2;
}
.Pageable(page => page.PageSizes(true))
.Scrollable(src => src.Height("auto"))
.Sortable()
.Filterable()
.Reorderable(reorder => reorder.Columns(true))
.ColumnMenu()
.Events(e =>
{
e.DataBound("onDataBound");
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("GetMyList_Read", "MyController"))
)
)
The datasource on this grid is loaded from "GetMyList_Read" action upon page load. I have a filter which works by pushing filter parameters into the kendo builtin filters. And it works fine. I want to do search on the serverside code to improve performance, instead of loading the whole data to the client side and filter. Also one of the search parameters require searching a new DB table evertime search is performed so having a server side filer will help a lot.
You can just alter your read action to include
.Read(read => read.Action("GetMyList_Read", "MyController").Data("AddFilters"))
Then add some JavaScript to populate you filters something like this:
<script>
Function AddFilters()
{
Return { filter: "some value");
}
</script>
Then just alter your read action to accept the additional parameter.
Eg public jsonresult GetMyList_Read([DataSourceRequest] DataSourceRequest request, string filter)
Hopefully this gives you enough to work with but if you need a more complete example let me know and I will post something a bit more complete