jqGrid中对列表cell数次那个格式话设置主要通过colModel中formatter,formatoptions来设置。

基本用法:

  1. jQuery("#jqGrid_id").jqGrid({
  2. ...
  3. colModel: [
  4. ...
  5. {name:'price', index:'price',  formatter:'integer', formatoptions:{thousandsSeparator: ','}},
  6. ...
  7. ]
  8. ...
  9. });

formatter主要是设置格式化类型(integer ,email等以及函数来支持自定义类型),formatoptions用来设置对应formatter的参数,

jqGrid中预定义了常见的格式及其options:

integer

thousandSeparator://千分位分隔符,

defaulValue

number

decimalSeparator,//小数分隔符,如"."

tousandsSwparator,//千分位分隔符,如","

decimalPlaces,//小数保留位数

defaulValue

currency

decimalSeparator, //小数分隔符,如"."
thousandsSeparator, //千分位分隔符,如","
decimalPlaces, //小数保留位数
defaulValue,
prefix //前缀,如加上"$"
suffix//后缀
date
srcformat, //source的本来格式
newformat //新格式
email
没有参数,会在该cell是email加上: mailto:name@domain.com
showlink
baseLinkUrl, //在当前cell中加入link的url,如"jq/query.action"
showAction, //在baseLinkUrl后加入&action=actionName
addParam, //在baseLinkUrl后加入额外的参数,如"&name=aaaa"
target,
idName     //默认会在baseLinkUrl后加入,如".action?id=1"。改如果设置idName="name",那么".action?name=1"。其中取值为当前rowid
checkbox
disabled      //true/false 默认为true此时的checkbox不能编辑,如当前cell的值是1、0会将1选中
select
设置下拉框,没有参数,需要和colModel里的editoptions配合使用
下面是一个使用的例子:
  1. var datas = [
  2. {"id":1,  "name":"name1",  "price":123.1,     "email":"abc@163.com",  "amount":1123423,   "gender":"1", "type":"0"},
  3. {"id":2,  "name":"name2",  "price":1452.2,    "email":"abc@163.com",  "amount":12212321,  "gender":"1", "type":"1"},
  4. {"id":3,  "name":"name3",  "price":125454,    "email":"abc@163.com",  "amount":2345234,   "gender":"0", "type":"0"},
  5. {"id":4,  "name":"name4",  "price":23232.4,   "email":"abc@163.com",  "amount":2345234,   "gender":"1", "type":"2"}]
  1. colModel:[
  2. {name:'id',     index:'id',     formatter:  customFmatter},
  3. {name:'name',   index:'name',   formatter: "showlink", formatoptions:{baseLinkUrl:"save.action",idName: "id", addParam:"&name=123"}},
  4. {name:'price',  index:'price',  formatter: "currency", formatoptions: {thousandsSeparator:",",decimalSeparator:".", prefix:"$"}},
  5. {name:'email',  index:'email',  formatter: "email"},
  6. {name:'amount', index:'amount', formatter: "number", formatoptions: {thousandsSeparator:",", defaulValue:"",decimalPlaces:3}},
  7. {name:'gender', index:'gender', formatter: "checkbox",formatoptions:{disabled:false}},
  8. {name:'type',   index:'type',   formatter: "select", editoptions:{value:"0:无效;1:正常;2:未知"}}
  9. ],
其中customFmatter声明如下
  1. function customFmatter(cellvalue, options, rowObject){
  2. console.log(cellvalue);
  3. console.log(options);
  4. console.log(rowObject);
  5. return "["+cellvalue+"]";
  6. };
 在页面显示的效果如下:
 
当然还得支持自定义formatter函数,只需要在formatter:customFmatter设置formatter函数,该函数有三个签名
  1. function customFmatter(cellvalue, options, rowObject){
  2. }
  3. //cellvalue - 当前cell的值
  4. //options - 该cell的options设置,包括{rowId, colModel,pos,gid}
  5. //rowObject - 当前cell所在row的值,如{ id=1, name="name1", price=123.1, ...}
 当然对于自定义formatter,在修改时需要获取原来的值,这里就提供了unformat函数,这里见官网的例子:
  1. jQuery("#grid_id").jqGrid({
  2. ...
  3. colModel: [
  4. ...
  5. {name:'price', index:'price', width:60, align:"center", editable: true, formatter:imageFormat, unformat:imageUnFormat},
  6. ...
  7. ]
  8. ...
  9. });
  10. function imageFormat( cellvalue, options, rowObject ){
  11. return '<img src="'+cellvalue+'" />';
  12. }
  13. function imageUnFormat( cellvalue, options, cell){
  14. return $('img', cell).attr('src');
  15. }
  附上官网DOC:

jqGrid中的formatter,表格中值的格式化的更多相关文章

  1. Flex中怎么给表格中的滚动栏定位

    1.问题背景 假设表格中的字段过多,会出现滚动栏,在将滚动栏滚到一定的位置时,又一次刷新表格.滚动栏会回到原处,原来查看的字段还得继续滚动,才干查看到. 2.实现实例 <? xml versio ...

  2. Flex中怎么给表格中的滚动条定位

    1.问题背景 如果表格中的字段过多,会出现滚动条,在将滚动条滚到一定的位置时,重新刷新表格,滚动条会回到原处,原来查看的字段还得继续滚动,才能查看到. 2.实现实例 <?xml version= ...

  3. Flex中单选按钮控制表格中的列的增加或减少

    1.问题背景 单选按钮有"苹果"和"香蕉"两个,表格中的列有星期.苹果.香蕉和苹果比率,选择了"苹果"单选按钮,表格显示星期.苹果和苹果比率 ...

  4. MySQL中导入Excel表格中的数据

    在数据库中建立好响应的数据库.表(参考excel表格中列中的名字和内容): 将excel表格另存为txt文件,选择“文本文件(制表符分割)”: 打开相应的txt文件,只留下要导入的数据(windows ...

  5. excel 怎么去掉单元格中第一个空格或其他特定符号/Excel excel中批量去掉表格中首字母前的空格或特定符号

    =IF(FIND(" ",A160)>1,A160,MID(A160,FIND(" ",A160)+1,LEN(A160)-FIND(" &qu ...

  6. oracle数据库中导入Excel表格中的数据

    1.点击[工具]-->[ODBC 导入器],如图: 2.在导入器里选择第一个[来自ODBC的数据],用户名/系统DSN-->填写[Excel Files],输入用户名和密码,点击 [连接] ...

  7. tp查询中2个表格中字段,比较大小

    $where['_string'] = '`has_number` < `number`';//~~~注意:这里`不能丢了: $coupon_flag = $coupon->where($ ...

  8. 利用java反射机制实现读取excel表格中的数据

    如果直接把excel表格中的数据导入数据库,首先应该将excel中的数据读取出来. 为了实现代码重用,所以使用了Object,而最终的结果是要获取一个list如List<User>.Lis ...

  9. vue表格中显示金额格式化与保存时格式化为数字并校验!

    最近项目中遇到了成本计算的,需要显示金额,保存一下,以后方便直接拿来用! 一 数字转金额格式显示 //数字转金额格式 format:function(s){ if(/[^0-9\.]/.test(s) ...

  10. dojo中获取表格中某一行的某个值

    dojo中经常出现对表格中的某行进行操作,如单击某行修改.删除等.那怎样获取某行的唯一标示呢? 如查询表格中的某列有个userId,并且这个是唯一的,那么可以通过它来访问这一列 具体操作代码如下: v ...

随机推荐

  1. bs4-BeautifulSoup

    1.BeautifulSoup下载 pip install BeautifulSoup4 或者 pip install bs4 pip install lxml #解析器 2.BeautifulSou ...

  2. Mybatis批处理(批量查询,更新,插入)

    mybatis批量查询 注意这里的 in 和   <trim prefix="(" suffix=")"> 以及 in ( )的三种方式的(例1(推 ...

  3. sea.js的同步魔法

    前些时间也是想写点关于CMD模块规范的文字,以便帮助自己理解.今天看到一篇知乎回答,算是给了我一点启发. 同步写法却不阻塞? 先上一个sea.js很经典的模块写法: // 定义一个模块 define( ...

  4. 根据屏幕分辨率判断当前手机型号(swift4.1)

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

  5. CSAPP - Ch 1 - 计算机系统漫游

    目录 0 序言及摘要 1 信息就是位+上下文 2 程序被其他程序翻译成不同的格式 3 了解编译系统如何工作是大有益处的 0 序言及摘要 (1) 序言: CS:APP -- Computer Syste ...

  6. spring boot application 配置详情

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  7. Delphi - Indy TIdFTP控件实现文件的上传和下载

    FTP信息保存和获取 我们在做FTP相关开发时,为方便后续FTP切换,一般先把FTP账户信息保存到数据库表中,在使用时再通过Query获取出来. 一般通过如下方式获取到FTP相关信息,代码如下: // ...

  8. Java 复制PPT幻灯片

    本篇文章将介绍通过java程序原样复制PPT幻灯片的方法.这里分两种情况来复制,即 在同一幻灯片文档中复制 在不同幻灯片文档间复制 使用工具:Free Spire.Presentation for J ...

  9. mongodb 启动 WARNING: soft rlimits too low, transparent_hugepage/enabled is 'always'. never

    今天启动mongodb的时候,之前一直没注意,今天发现又warning,想整一整. 下面是告警 2019-09-05T12:00:55.271+0800 I CONTROL [initandliste ...

  10. STL中的map和multimap小结

    (1)使用map/multimap之前必须包含头文件<map>:#include<map> 并且和所有的关联式容器一样,map/multimap通常以平衡二叉树来完成    ( ...