easyui中formatter的用法

easyui中formatter的用法

 

当我们使用easyui需要对某一列进行格式化处理value数据时,可以使用formatter进行格式化

这里以一个商品表举例,商品表中有一个商品类型的字段,数据类型为int,想通过formatter方法来实现:
  • 商品类型值为0时,前端将显示“主体商品”。
  • 商品类型值为1时,前端将显示“附属商品”。
      • value:字段值

      • row:行记录数据

      • index:行所在索引

      js代码:

      $(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 '附属商品';
                      }
                  }        
                 }
              ]]        
          });
      }); 

       

      html代码:

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

       

posted @ 2019-09-05 01:06  落成  阅读(2021)  评论(0编辑  收藏  举报