datagrid的数据是通过请求一个url地址,这个地址返回来json数据
这个json数据是要符合datagrid的格式
然后easyui的js 会自动把这个json文档 解析 渲染成一个表格
比如官网的例子 就是请求这个
返回来的json文档是{"total":"4","rows":[{"id":"82709","firstname":"aaaaaa","lastname":"last name","phone":"fsadfwe","email"
:"d@d.com"},{"id":"82713","firstname":"sdf","lastname":"asdf","phone":"asf","email":"asdf@cds.com"},
{"id":"82714","firstname":"sdf","lastname":"asdf","phone":"asdf","email":"asdf@asdf.com"},{"id":"82715"
,"firstname":"sdf","lastname":"asdf","phone":"asdf","email":"asdf@asdf.com"}]} 我们直接去请求一个地址
<table
url="/manage/LoadCatalog"
toolbar="#toolbar" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="Name">栏目名称</th>
<th field="AddTime">添加时间</th>
</tr>
</thead>
</table> 写一个返回json的action
public JsonResult LoadCatalog()
{
using (BamnBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext())
{
var list = dbContext.Catalogs.ToList();
return Json(list);
}
} 留了一个问题日期列无法现实正确的时间
我们在视图中添加一列
<th data-options="field:'_operate',width:80,align:'center',formatter:formatOper">操作</th>
然后再写一个格式化的方法
<script type="text/javascript">
function formatOper(val, row, index) {
return '<a href="#">修改</a>';
}
</script>