Anybody else have this problem?
Any help would be appreciated!
Visual Studio Premium 2012
Package Installation Error
The "repository" attribute of the package element has an invalid value:
'registry'. Valid values are 'template', or 'extension'
Thanks!
I'm just building my first kendo app - and my first mvc app, for that matter - and am stuck on one piece. The page has a kendo grid that is populated using the View's model. Above the grid is a search form, which triggers a "Search" controller action. That action uses any criteria to get a new set of data and passes it back to the View, but the grid doesn't automatically re-bind to the data. I'm not sure how to re-bind the grid, but if there is a way, where would I do it - in the View or the controller action?
Here is my code - Grid:
@(Html.Kendo().Grid(Model)
.Name("tblGrid")
.Columns(columns =>
{
columns.Bound(w => w.Id).Hidden();
columns.Bound(w => w.IncidentType).Width(160);
columns.Bound(w => w.Location).Width(180);
columns.Bound(w => w.IncidentDateTime).Width(120).Format("{0: MM/dd/yyyy H:mm tt}");
columns.Bound(w => w.PostDateTime).Width(120).Format("{0: MM/dd/yyyy H:mm tt}");
})
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(w => w.Id))
.PageSize(15)
.Create("Editing_Create", "Grid")
)
.Events(events => events.Change("gridChange"))
.Groupable()
.Pageable()
.Sortable()
.Selectable()
.Resizable(builder => builder.Columns(true))
)
Search Controller:
[HttpPost]
public
ActionResult Search([DataSourceRequest] DataSourceRequest request,
string
location,
string
reportNum,
int
? officerId,
int
? xref,
int
? days,
int
incidentTypeId)
{
var summaries =
new
List<WatchSummaryInfo>();
try
{
summaries = WatchSummaryBL.DoGetWatchListBySearch(SearchCriteriaHere).ToList();
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
var filtered =
new
List<WatchSummaryViewModel>();
try
{
foreach
(var summary
in
summaries)
{
filtered.Add(
new
WatchSummaryViewModel{
Id = summary.ID,
IncidentDateTime = summary.WatchDateTime,
IncidentType = summary.IncidentType,
Location = summary.Location,
PostDateTime = summary.PostDateTime
});
}
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
return
View(
"List"
, filtered);
}
I can verify by stepping through this that the collection I am passing back to the View has a much smaller subset (11) than the original ViewModel data, but the grid doesn't change.
What am I missing?
Thanks for the help!
Eddie
Is there a way to disable column resizing for a particular column only (the last column to be precise)?
Some more info on my problem, I have enabled fixed table layout on the Grid, so that an Ellipsis will show for fields that are very long.
/* allow ellipsis to show on overflow text in grid */
.k-grid table
{
table-layout:fixed;
}
... but now when the user resizes the last column, there are rendering issues on the Grid - it overruns the width of the grid (see attachment).
Here is my grid def -
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.RoleName).Width(200);
columns.Bound(p => p.Description);
})
.Events(events => events.Change("Grid_OnRowSelect"))
.Pageable()
.Sortable()
.HtmlAttributes(new { @style = "width:500px" })
.Selectable(s => s.Mode(GridSelectionMode.Single))
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("RoleSearch", "Role").Data("Grid_OnData"))
.Events(e => e.RequestEnd("Grid_OnRequestEnd"))
)
)
@model System.Collections.IEnumerable
@(Html.Kendo().Grid<
HoghoughModel.PTStbKarkonan
>()
.Name("Grid")
.EnableCustomBinding(true)
.BindTo(Model)
.Columns(columns => {
columns.Bound(o => o.IssuePlace);
columns.Bound(o => o.BimehName);
columns.Bound(o => o.Family);
columns.Bound(o => o.Name);
})
.Pageable()
.Sortable()
.Filterable()
.Scrollable()
.Groupable()
.DataSource(dataSource => dataSource.Server().Total((int)ViewData["total"]))
)
public
ActionResult Index([DataSourceRequest(Prefix =
"Grid"
)] DataSourceRequest request)
{
if
(request.PageSize == 0)
{
request.PageSize = 10;
}
IQueryable<PTStbKarkonan> karkonan = db.PTStbKarkonans;
karkonan = karkonan.ApplyFiltering(request.Filters);
var total = karkonan.Count();
karkonan = karkonan.ApplySorting(request.Groups, request.Sorts);
karkonan = karkonan.ApplyPaging(request.Page, request.PageSize);
IEnumerable data = karkonan.ApplyGrouping(request.Groups);
ViewData[
"total"
] = total;
return
View(data);
}
public
static
class
PTStbKarkonanExtensions
{
public
static
IQueryable<PTStbKarkonan> ApplyPaging(
this
IQueryable<PTStbKarkonan> data,
int
page,
int
pageSize)
{
if
(pageSize > 0 && page > 0)
{
data = data.Skip((page - 1) * pageSize);
}
data = data.Take(pageSize);
return
data;
}
public
static
IEnumerable ApplyGrouping(
this
IQueryable<PTStbKarkonan> data, IList<GroupDescriptor>
groupDescriptors)
{
if
(groupDescriptors !=
null
&& groupDescriptors.Any())
{
Func<IEnumerable<PTStbKarkonan>, IEnumerable<AggregateFunctionsGroup>> selector =
null
;
foreach
(var group
in
groupDescriptors.Reverse())
{
if
(selector ==
null
)
{
if
(group.Member ==
"IssuePlace"
)
{
selector = Orders => BuildInnerGroup(Orders, o => o.IssuePlace);
}
else
if
(group.Member ==
"BimehName"
)
{
selector = Orders => BuildInnerGroup(Orders, o => o.BimehName);
}
else
if
(group.Member ==
"Family"
)
{
selector = Orders => BuildInnerGroup(Orders, o => o.Family);
}
else
if
(group.Member ==
"Name"
)
{
selector = Orders => BuildInnerGroup(Orders, o => o.Name);
}
}
else
{
if
(group.Member ==
"IssuePlace"
)
{
selector = BuildGroup(o => o.IDSeri, selector);
}
else
if
(group.Member ==
"BimehName"
)
{
selector = BuildGroup(o => o.BimehName, selector);
}
else
if
(group.Member ==
"Family"
)
{
selector = BuildGroup(o => o.Family, selector);
}
else
if
(group.Member ==
"Name"
)
{
selector = BuildGroup(o => o.Name, selector);
}
}
}
return
selector.Invoke(data).ToList();
}
return
data;
}
private
static
Func<IEnumerable<PTStbKarkonan>, IEnumerable<AggregateFunctionsGroup>>
BuildGroup<T>(Expression<Func<PTStbKarkonan, T>> groupSelector, Func<IEnumerable<PTStbKarkonan>,
IEnumerable<AggregateFunctionsGroup>> selectorBuilder)
{
var tempSelector = selectorBuilder;
return
g => g.GroupBy(groupSelector.Compile())
.Select(c =>
new
AggregateFunctionsGroup
{
Key = c.Key,
HasSubgroups =
true
,
Member = groupSelector.MemberWithoutInstance(),
Items = tempSelector.Invoke(c).ToList()
});
}
private
static
IEnumerable<AggregateFunctionsGroup> BuildInnerGroup<T>(IEnumerable<PTStbKarkonan>
group, Expression<Func<PTStbKarkonan, T>> groupSelector)
{
return
group.GroupBy(groupSelector.Compile())
.Select(i =>
new
AggregateFunctionsGroup
{
Key = i.Key,
Member = groupSelector.MemberWithoutInstance(),
Items = i.ToList()
});
}
public
static
IQueryable<PTStbKarkonan> ApplySorting(
this
IQueryable<PTStbKarkonan> data,
IList<GroupDescriptor> groupDescriptors, IList<SortDescriptor> sortDescriptors)
{
if
(groupDescriptors !=
null
&& groupDescriptors.Any())
{
foreach
(var groupDescriptor
in
groupDescriptors.Reverse())
{
data = AddSortExpression(data, groupDescriptor.SortDirection, groupDescriptor.Member);
}
}
if
(sortDescriptors !=
null
&& sortDescriptors.Any())
{
foreach
(SortDescriptor sortDescriptor
in
sortDescriptors)
{
data = AddSortExpression(data, sortDescriptor.SortDirection, sortDescriptor.Member);
}
}
return
data;
}
private
static
IQueryable<PTStbKarkonan> AddSortExpression(IQueryable<PTStbKarkonan> data, ListSortDirection
sortDirection,
string
memberName)
{
if
(sortDirection == ListSortDirection.Ascending)
{
switch
(memberName)
{
case
"IssuePlace"
:
data = data.OrderBy(order => order.IssuePlace);
break
;
case
"BimehName"
:
data = data.OrderBy(order => order.BimehName);
break
;
case
"Family"
:
data = data.OrderBy(order => order.Family);
break
;
case
"Name"
:
data = data.OrderBy(order => order.Name);
break
;
}
}
else
{
switch
(memberName)
{
case
"IssuePlace"
:
data = data.OrderByDescending(order => order.IssuePlace);
break
;
case
"BimehName"
:
data = data.OrderByDescending(order => order.BimehName);
break
;
case
"Family"
:
data = data.OrderByDescending(order => order.Family);
break
;
case
"Name"
:
data = data.OrderByDescending(order => order.Name);
break
;
}
}
return
data;
}
public
static
IQueryable<PTStbKarkonan> ApplyFiltering(
this
IQueryable<PTStbKarkonan> data,
IList<IFilterDescriptor> filterDescriptors)
{
if
(filterDescriptors !=
null
&& filterDescriptors.Any())
{
data = data.Where(ExpressionBuilder.Expression<PTStbKarkonan>(filterDescriptors));
}
return
data;
}
}
@(Html.Kendo().Grid(Model.ExtensionDetails)
.Name("ExtensionInfoGrid")
.Columns(columns =>
{
columns.Bound(o => o.Selected)
.Title("")
.Width(50)
.ClientTemplate("<
input
type
=
'checkbox'
id
=
'isSelected'
name
=
'isSelected'
#if(Selected){#checked#}#
value
=
'#=Selected#'
/>")
.EditorTemplateName("Checkbox");
columns.Bound(o => o.ExtendFromDate)
.Title("Extend From Date *")
.Width(150)
.Format("{0:M/d/yyyy}")
.Filterable(false)
.Sortable(true)
.EditorTemplateName("Date");
columns.Bound(o => o.Units)
.Title("Units *")
.Width(100)
.EditorTemplateName("Integer");
columns.Bound(o => o.UnitType).Title("Unit Type");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Model(model =>
{
model.Id(m => m.Code);
model.Field(m => m.Selected).Editable(true);
model.Field(m => m.ExtendFromDate).Editable(true).DefaultValue(DateTime.Now);
model.Field(m => m.Units).Editable(true);
model.Field(m => m.UnitType).Editable(false);
})
)
)}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ProviderWebAppMVC.UmServiceRef;
namespace ProviderWebAppMVC.Models
{
public class ExtensionDetail
{
public ExtensionDetail()
{
Selected = true;
Code = string.Empty;
Description = string.Empty;
ExtendFromDate = DateTime.Now;
ExtendToDate = DateTime.Now;
Units = 0;
UnitType = string.Empty;
}
public bool Selected;
public string Code;
public string Description;
public DateTime ExtendFromDate;
public DateTime ExtendToDate;
public int Units { get; set; }
public string UnitType { get; set; }
}
}