easyUI dategrid field 用formatter显示子属性
2015-04-01 22:45
176 查看
dategrid:
这里,book和bookType是多对一的关系,后台返回的json中,bookType又是一个json对象,要获得bookType的bookTypeName,不能直接用bookType.bookTypeName .所以在field的bookType字段加上formatter 。
val是该字段的值,即bookType。row是行值。这里注意,要加一个if为空的判断,因为我有的书籍没有设置类型,这样的话就会找不到类型名,造成整个date都没有显示数据了。
<body class="easyui-layout" data-options="fit:true,border:false"> <table id="dg" class="easyui-datagrid" data-options="fit:true,border:false" url="book/listBookForUser" toolbar="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true"> <thead> <tr> <th field="bookId" width="50">书ID</th> <th field="bookName" width="50">书名</th> <th field="bookType" width="50" formatter="formatBookType">书类型</th> <th field="author" width="50">作者</th> <th field="callNumber" width="50">索书号</th> <th field="iSBN" width="50">ISBN</th> <th field="publisher" width="50">出版社</th> <th field="publishYear" width="50">出版年份</th> <th field="series" width="50">系列</th> <th field="language" width="50">语言</th> <th field="price" width="50">价格</th> <th field="page" width="50">页数</th> </tr> </thead> </table>
这里,book和bookType是多对一的关系,后台返回的json中,bookType又是一个json对象,要获得bookType的bookTypeName,不能直接用bookType.bookTypeName .所以在field的bookType字段加上formatter 。
function formatBookType(val,row,index){ //alert(row.bookType); if(val==null){ return ""; }else return row.bookType.bookTypeName; }
val是该字段的值,即bookType。row是行值。这里注意,要加一个if为空的判断,因为我有的书籍没有设置类型,这样的话就会找不到类型名,造成整个date都没有显示数据了。
相关文章推荐
- 当使用EasyUI时,需要的Field属性是子属性时候,除了formatter和修改jquery.easyui.min.js的方法
- 更改EasyUI的DataGrid的显示信息。使用formatter属性,将数据库中存储的gender为1 or 0修改为“男”or“女”。
- easyui中datagrid如何使用formatter显示子对象的属性
- easyui datagrid 表格组件列属性formatter和styler使用方法
- EasyUI datagrid显示子对象里的属性
- easyui datagrid columns的field支持属性的子属性(field.sonfield形式或者格式化程序形式)
- easyui datagrid 表格组件列属性formatter和styler使用方法
- easyui datagrid columns的field支持属性的子属性(field.sonfield形式或者格式化程序形式)
- springmvc+easyui datagrid columns的field支持属性的子属性(field.sonfield形式或者格式化程序形式)
- easyui datagrid columns的field支持属性的子属性(field.sonfield形式或者格式化程序形式)
- EasyUI DataGrid使用formatter属性实现自定义功能
- easyui的formatter属性的用法
- 解决Custom Field Type修改时属性显示不正确的问题
- easyui的formatter属性的用法
- easyui datagrid 表格组件列属性formatter和styler使用方法
- easyUI-datagrid属性设置display:none,加载数据或表头不显示
- EasyUI DataGrid使用formatter属性实现自定义功能
- VCL(四) 如何写出象TTable, TAdoTable ,Tquery,TAdoQuery 等控件一样的自动下拉显示Field属性
- easyui 表格中combo选择值后显示为valueField而非textField的解决
- VCL(四)如何写出象TTable, TAdoTable ,Tquery,TAdoQuery 等控件一样的自动下拉显示Field属性