jqGrid中的formatter,表格中值的格式化
jqGrid中对列表cell数次那个格式话设置主要通过colModel中formatter,formatoptions来设置。
基本用法:
- jQuery("#jqGrid_id").jqGrid({
- ...
- colModel: [
- ...
- {name:'price', index:'price', formatter:'integer', formatoptions:{thousandsSeparator: ','}},
- ...
- ]
- ...
- });
formatter主要是设置格式化类型(integer ,email等以及函数来支持自定义类型),formatoptions用来设置对应formatter的参数,
jqGrid中预定义了常见的格式及其options:
integer
thousandSeparator://千分位分隔符,
defaulValue
number
decimalSeparator,//小数分隔符,如"."
tousandsSwparator,//千分位分隔符,如","
decimalPlaces,//小数保留位数
defaulValue
currency
- var datas = [
- {"id":1, "name":"name1", "price":123.1, "email":"abc@163.com", "amount":1123423, "gender":"1", "type":"0"},
- {"id":2, "name":"name2", "price":1452.2, "email":"abc@163.com", "amount":12212321, "gender":"1", "type":"1"},
- {"id":3, "name":"name3", "price":125454, "email":"abc@163.com", "amount":2345234, "gender":"0", "type":"0"},
- {"id":4, "name":"name4", "price":23232.4, "email":"abc@163.com", "amount":2345234, "gender":"1", "type":"2"}]
- colModel:[
- {name:'id', index:'id', formatter: customFmatter},
- {name:'name', index:'name', formatter: "showlink", formatoptions:{baseLinkUrl:"save.action",idName: "id", addParam:"&name=123"}},
- {name:'price', index:'price', formatter: "currency", formatoptions: {thousandsSeparator:",",decimalSeparator:".", prefix:"$"}},
- {name:'email', index:'email', formatter: "email"},
- {name:'amount', index:'amount', formatter: "number", formatoptions: {thousandsSeparator:",", defaulValue:"",decimalPlaces:3}},
- {name:'gender', index:'gender', formatter: "checkbox",formatoptions:{disabled:false}},
- {name:'type', index:'type', formatter: "select", editoptions:{value:"0:无效;1:正常;2:未知"}}
- ],
- function customFmatter(cellvalue, options, rowObject){
- console.log(cellvalue);
- console.log(options);
- console.log(rowObject);
- return "["+cellvalue+"]";
- };

- function customFmatter(cellvalue, options, rowObject){
- }
- //cellvalue - 当前cell的值
- //options - 该cell的options设置,包括{rowId, colModel,pos,gid}
- //rowObject - 当前cell所在row的值,如{ id=1, name="name1", price=123.1, ...}
- jQuery("#grid_id").jqGrid({
- ...
- colModel: [
- ...
- {name:'price', index:'price', width:60, align:"center", editable: true, formatter:imageFormat, unformat:imageUnFormat},
- ...
- ]
- ...
- });
- function imageFormat( cellvalue, options, rowObject ){
- return '<img src="'+cellvalue+'" />';
- }
- function imageUnFormat( cellvalue, options, cell){
- return $('img', cell).attr('src');
- }
jqGrid中的formatter,表格中值的格式化的更多相关文章
- Flex中怎么给表格中的滚动栏定位
1.问题背景 假设表格中的字段过多,会出现滚动栏,在将滚动栏滚到一定的位置时,又一次刷新表格.滚动栏会回到原处,原来查看的字段还得继续滚动,才干查看到. 2.实现实例 <? xml versio ...
- Flex中怎么给表格中的滚动条定位
1.问题背景 如果表格中的字段过多,会出现滚动条,在将滚动条滚到一定的位置时,重新刷新表格,滚动条会回到原处,原来查看的字段还得继续滚动,才能查看到. 2.实现实例 <?xml version= ...
- Flex中单选按钮控制表格中的列的增加或减少
1.问题背景 单选按钮有"苹果"和"香蕉"两个,表格中的列有星期.苹果.香蕉和苹果比率,选择了"苹果"单选按钮,表格显示星期.苹果和苹果比率 ...
- MySQL中导入Excel表格中的数据
在数据库中建立好响应的数据库.表(参考excel表格中列中的名字和内容): 将excel表格另存为txt文件,选择“文本文件(制表符分割)”: 打开相应的txt文件,只留下要导入的数据(windows ...
- excel 怎么去掉单元格中第一个空格或其他特定符号/Excel excel中批量去掉表格中首字母前的空格或特定符号
=IF(FIND(" ",A160)>1,A160,MID(A160,FIND(" ",A160)+1,LEN(A160)-FIND(" &qu ...
- oracle数据库中导入Excel表格中的数据
1.点击[工具]-->[ODBC 导入器],如图: 2.在导入器里选择第一个[来自ODBC的数据],用户名/系统DSN-->填写[Excel Files],输入用户名和密码,点击 [连接] ...
- tp查询中2个表格中字段,比较大小
$where['_string'] = '`has_number` < `number`';//~~~注意:这里`不能丢了: $coupon_flag = $coupon->where($ ...
- 利用java反射机制实现读取excel表格中的数据
如果直接把excel表格中的数据导入数据库,首先应该将excel中的数据读取出来. 为了实现代码重用,所以使用了Object,而最终的结果是要获取一个list如List<User>.Lis ...
- vue表格中显示金额格式化与保存时格式化为数字并校验!
最近项目中遇到了成本计算的,需要显示金额,保存一下,以后方便直接拿来用! 一 数字转金额格式显示 //数字转金额格式 format:function(s){ if(/[^0-9\.]/.test(s) ...
- dojo中获取表格中某一行的某个值
dojo中经常出现对表格中的某行进行操作,如单击某行修改.删除等.那怎样获取某行的唯一标示呢? 如查询表格中的某列有个userId,并且这个是唯一的,那么可以通过它来访问这一列 具体操作代码如下: v ...
随机推荐
- Nginx+Zuul集群实现高可用网关
代码参考:https://github.com/HCJ-shadow/Zuul-Gateway-Cluster-Nginx Zuul的路由转发功能 前期准备 搭建Eureka服务注册中心 服务提供者m ...
- SpringMVC源码分析2:SpringMVC设计理念与DispatcherServlet
转自:https://my.oschina.net/lichhao/blog SpringMVC简介 SpringMVC作为Struts2之后异军突起的一个表现层框架,正越来越流行,相信javaee的 ...
- CSS布局:元素水平居中
CSS布局之元素水平居中 本文将依次介绍在不同条件下实现水平居中多种方法 一.使用 text-align: center : 适用于块级元素内部的行内元素水平居中(也适用于图片的水平居中) 此方法对i ...
- Python-demo(photo)
import osimport urllib import requests#import wximport time from fake_useragent import UserAgentfrom ...
- 消息中间件——RabbitMQ(八)高级特性全在这里!(下)
前言 上一篇消息中间件--RabbitMQ(七)高级特性全在这里!(上)中我们介绍了消息如何保障100%的投递成功?,幂等性概念详解,在海量订单产生的业务高峰期,如何避免消息的重复消费的问题?,Con ...
- Maven项目添加ojdbc8
1.找到Oracle中的ojdbc8,它的位置在Oracle客户端 2.找到它的位置后,把你放ojdbc8的位置复制,改如下代码"D:\ojdbc8.jar"为你的ojdbc8位置 ...
- Redis学习总结(二)--Redis数据结构
Redis支持六种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). 结构类型 存储的值 string 可以是字符串.浮 ...
- centos7yum安装mysql5.7
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7 https://typecodes. ...
- MSIL实用指南-生成break和continue
break和continue本质都是标签的跳转
- linux 网络基础之IP地址
IP是英文Internet Protocol的缩写,意思是“网络之间互连的协议”,也就是为计算机网络相互连接进行通信而设计的协议. IP地址类型分为:公有地址.私有地址. 公有地址 公有地址(Publ ...