Asp.net mvc 4 宽度:80,可排序:true,对齐:'left'}, {显示:'ModifiedOn',名称:'ModifiedOn',宽度:60,可排序:true,对齐:'left'} ], 搜索项目:[ {显示:'NotificationID',名称:'NotificationID'}, {显示:'通知',名称:'通知'}, {display:'IsDisplay',name:'IsDisplay'}, {display:'CreatedBy',name:'CreatedBy'}, {显示:'CreatedOn',名称:'CreatedOn'}, {显示:'ModifiedBy',名称:'ModifiedBy'} ], sortname:'NotificationId', 排序器:“asc”, 是的, 标题:“通知”, useRp:是的, rp:15, showTableToggleBtn:正确, 宽度:1040, 身高:380 }); });
另外,让脚本驻留在表布局中可能不是最好的主意。做一个标签汤Asp.net mvc 4 宽度:80,可排序:true,对齐:'left'}, {显示:'ModifiedOn',名称:'ModifiedOn',宽度:60,可排序:true,对齐:'left'} ], 搜索项目:[ {显示:'NotificationID',名称:'NotificationID'}, {显示:'通知',名称:'通知'}, {display:'IsDisplay',name:'IsDisplay'}, {display:'CreatedBy',name:'CreatedBy'}, {显示:'CreatedOn',名称:'CreatedOn'}, {显示:'ModifiedBy',名称:'ModifiedBy'} ], sortname:'NotificationId', 排序器:“asc”, 是的, 标题:“通知”, useRp:是的, rp:15, showTableToggleBtn:正确, 宽度:1040, 身高:380 }); });,asp.net-mvc-4,kendo-ui,flexigrid,Asp.net Mvc 4,Kendo Ui,Flexigrid,另外,让脚本驻留在表布局中可能不是最好的主意。做一个标签汤 <table id="notification" style="display:none"> <script type="text/javascript"> $("#notifications").flexigrid({ url: 'Controllers/Notifications/NotificationsList', dataType:
<table id="notification" style="display:none">
<script type="text/javascript">
$("#notifications").flexigrid({
url: 'Controllers/Notifications/NotificationsList',
dataType: 'json',
colModel: [
{ display: 'NotificationID', name: 'NotificationID', width: 40, sortable: true, align: 'left' },
{ display: 'Notification', name: 'Notification', width: 100, sortable: true, align: 'left' },
{ display: 'IsDisplay', name: 'IsDisplay', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedBy', name: 'CreatedBy', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedOn', name: 'CreatedOn', width: 100, sortable: true, align: 'left' },
{ display: 'ModifiedBy', name: 'ModifiedBy', width: 80, sortable: true, align: 'left' },
{ display: 'ModifiedOn', name: 'ModifiedOn', width: 60, sortable: true, align: 'left' }
],
searchitems: [
{ display: 'NotificationID', name: 'NotificationID' },
{ display: 'Notification', name: 'Notification' },
{ display: 'IsDisplay', name: 'IsDisplay' },
{ display: 'CreatedBy', name: 'CreatedBy' },
{ display: 'CreatedOn', name: 'CreatedOn' },
{ display: 'ModifiedBy', name: 'ModifiedBy' }
],
sortname: 'NotificationId',
sortorder: 'asc',
usepager: true,
title: 'Notifications',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 1040,
height: 380
});
</script>
</table>
}
public ActionResult NotificationsList()
{
var q = from c in db.Tbl_Notification
select c;
List<Tbl_Notification> notes = q.ToList();
FlexigridObject flexigridObject = new FlexigridObject();
flexigridObject.page = 1;
flexigridObject.total = db.Tbl_Notification.Count();
foreach (Tbl_Notification notify in notes)
{
FlexigridRow cell = new FlexigridRow()
{
id = notify.NotificationId,
cell = GetPropertyList(notify)
};
flexigridObject.rows.Add(cell);
}
return View("FlexigridObject", flexigridObject);
}
private List<string> GetPropertyList(object obj)
{
List<string> propertyList = new List<string>();
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (PropertyInfo property in properties)
{
object o = property.GetValue(obj, null);
propertyList.Add(o == null ? "" : o.ToString());
}
return propertyList;
}
}
public static class ExtensionMethods
{
public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string propertyName, bool asc)
{
var type = typeof(T);
string methodName = asc ? "OrderBy" : "OrderByDescending";
var property = type.GetProperty(propertyName);
var parameter = Expression.Parameter(type, "p");
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var orderByExp = Expression.Lambda(propertyAccess, parameter);
MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName, new Type[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
return source.Provider.CreateQuery<T>(resultExp);
}
public static IQueryable<T> Like<T>(this IQueryable<T> source, string propertyName, string keyword)
{
var type = typeof(T);
var property = type.GetProperty(propertyName);
var parameter = Expression.Parameter(type, "p");
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var constant = Expression.Constant("%" + keyword + "%");
MethodCallExpression methodExp = Expression.Call(null, typeof(SqlMethods).GetMethod("Like", new Type[] { typeof(string), typeof(string) }), propertyAccess, constant);
Expression<Func<T, bool>> lambda = Expression.Lambda<Func<T, bool>>(methodExp, parameter);
return source.Where(lambda);
}
}
<table id="notification" style="display:none">
<script type="text/javascript">
$(document).ready(function () {
$("#notifications").flexigrid({
url: 'Controllers/Notifications/NotificationsList',
dataType: 'json',
colModel: [
{ display: 'NotificationID', name: 'NotificationID', width: 40, sortable: true, align: 'left' },
{ display: 'Notification', name: 'Notification', width: 100, sortable: true, align: 'left' },
{ display: 'IsDisplay', name: 'IsDisplay', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedBy', name: 'CreatedBy', width: 100, sortable: true, align: 'left' },
{ display: 'CreatedOn', name: 'CreatedOn', width: 100, sortable: true, align: 'left' },
{ display: 'ModifiedBy', name: 'ModifiedBy', width: 80, sortable: true, align: 'left' },
{ display: 'ModifiedOn', name: 'ModifiedOn', width: 60, sortable: true, align: 'left' }
],
searchitems: [
{ display: 'NotificationID', name: 'NotificationID' },
{ display: 'Notification', name: 'Notification' },
{ display: 'IsDisplay', name: 'IsDisplay' },
{ display: 'CreatedBy', name: 'CreatedBy' },
{ display: 'CreatedOn', name: 'CreatedOn' },
{ display: 'ModifiedBy', name: 'ModifiedBy' }
],
sortname: 'NotificationId',
sortorder: 'asc',
usepager: true,
title: 'Notifications',
useRp: true,
rp: 15,
showTableToggleBtn: true,
width: 1040,
height: 380
});
});
</script>
</table>