easyui中formatter的用法

95 阅读1分钟
当我们使用easyui需要对某一列进行格式化处理value数据时,可以使用formatter进行格式化
这里以一个商品表举例,商品表中有一个商品类型的字段,数据类型为int,想通过formatter方法来实现:
  • 商品类型值为0时,前端将显示“主体商品”。
  • 商品类型值为1时,前端将显示“附属商品”。
      • value:字段值
      • row:行记录数据
      • index:行所在索引

      js代码:
      [url=][/url]

      $(
      function
      (){ $('#dg').datagrid({ url:"${pageContext.request.contextPath}/OfferServlet",
      //
      servlet路径
      columns:[[ {field:'offertype',title:'商品类型',width:100,formatter:
      function
      (value,row,index){
      if
      (value == '0'){
      return
      '主体商品'; }
      else
      if
      (value == '1'){
      return
      '附属商品'; } } } ]] });});
      [url=][/url]



      html代码:
      <
      table
      id
      ="dg"
      title
      ="用户列表"
      class
      ="easyui-datagrid"
      style
      ="width:1000px;height:250px"
      toolbar
      ="#toolbar"
      >
      </
      table
      >