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 ...
随机推荐
- java 程序执行顺序之继承
1.首先会初始化父类,因为没有父类子类也无从谈起.第一步初始化static 变量 或者 静态初始化话块 2.初始化子类的static 变量 或者 静态初始化块 3.顺序初始化父类普通变量 或者 父类普 ...
- idea(java)实用开发插件
Idea常用的插件: mybatisX, ---------------- (Alt + enter) codeGlace, Lombok, sonarlint, translation, ...
- 消息中间件——RabbitMQ(七)高级特性全在这里!(上)
前言 前面我们介绍了RabbitMQ的安装.各大消息中间件的对比.AMQP核心概念.管控台的使用.快速入门RabbitMQ.本章将介绍RabbitMQ的高级特性.分两篇(上/下)进行介绍. 消息如何保 ...
- PythonI/O进阶学习笔记_1.抽象、面向对象、class/object/type
前言: 是自己在学习python进阶IO学习视频的时候的理解和笔记,因为很多都是本菜鸟学习时候的自己的理解,有可能理解有误. Content: - 抽象的概念和面向对象的概念?想要大概了解python ...
- Codeforces 985E
题意略. 思路: 这个题目开始想的有点暴力,后来发现有搜索的性质,因此转而用动态规划.首先,我们要把这些数排个序. 定义状态:dp[i]为排序后i~n能否成功打包,1表示可以,0表示不能打包. 状态转 ...
- HTTP网页异常错误代码详解
在调试TomCat,等web服务器的时候我们有时候各种错误代码铺面而来,让人头疼不已,那么这些代码究竟都代表什么呢?知道这些代码会会对我们的调试帮助很大 让我们来看一下这些代码究竟什么意思 400 无 ...
- Python 内存分配时的小秘密
Python 中的sys 模块极为基础而重要,它主要提供了一些给解释器使用(或由它维护)的变量,以及一些与解释器强交互的函数. 本文将会频繁地使用该模块的getsizeof() 方法,因此,我先简要介 ...
- Delphi - cxGrid内容xlsx、xls、csv格式导出
.xls格式导出,uses中添加cxGridExportLink 代码如下: function SaveToExcel(gridMain: TcxGrid; FileName: string): st ...
- POJ-1984-Navigation Nightmare+带权并查集(中级
传送门:Navigation Nightmare 参考:1:https://www.cnblogs.com/huangfeihome/archive/2012/09/07/2675123.html 参 ...
- poj 1797Heavy Transportation(dijkstra变形)
题目链接:http://poj.org/problem?id=1797 题意:有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上 ...