jQuery EasyUI 数据网格 – 格式化列

jQuery EasyUI 数据网格 – 格式化列

以下实例格式化在easyui DataGrid里的列数据,并使用自定义列的formatter,如果价格小于20,则文本变为红色。

jQuery EasyUI 数据网格 – 格式化列

为了格式化一个数据网格(DataGrid)列,我们需要设置formatter属性,它是一个函数。这个格式化函数包含三个参数:

  • value:当前列对应字段值。
  • row:当前的行记录数据。
  • index:当前的行下标。

创建数据网格(DataGrid)

	<table id="tt" title="Formatting Columns" class="easyui-datagrid" style="" url="data/datagrid_data.json" 	     singleSelect="true" iconCls="icon-save">
		<thead>
			<tr>
				<th field="itemid" width="80">Item ID</th>
				<th field="productid" width="80">Product ID</th>
				<th field="listprice" width="80" align="right" formatter="formatPrice">List Price</th>
				<th field="unitcost" width="80" align="right">Unit Cost</th>
				<th field="attr1" width="100">Attribute</th>
				<th field="status" width="60" align="center">Stauts</th>
			</tr>
		</thead>
	</table>

请注意,listprice字段有一个formatter属性,用来指明格式化函数。

写格式化函数

	function formatPrice(val,row){
		if (val < 20){ 	return <span style="">(+val+)</span>;
		} else {
			return val;
		}
	}

下载 jQuery EasyUI 实例

jeasyui-datagrid-datagrid7.zip

作者:冒牌SEO,如若转载,请注明出处:https://www.web176.com/easyui/14723.html

(0)
打赏 支付宝 支付宝 微信 微信
冒牌SEO冒牌SEO
上一篇 2023年3月31日
下一篇 2023年3月31日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注