您当前的位置: 首页 >  ui

杨林伟

暂无认证

  • 0浏览

    0关注

    3337博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

35EasyUI 数据网格- 列运算

杨林伟 发布时间:2019-04-17 17:40:50 ,浏览量:0

一个运算列通常包含一些从一个或多个其他列运算的值。 在这里插入图片描述

首先,创建一个可编辑的数据网格(datagrid)。这里我们创建了一些可编辑列,‘listprice’、‘amount’ 和 ‘unitcost’ 列定义为 numberbox 编辑类型。运算列是 ‘unitcost’ 字段,将是 listprice 乘以 amount 列的结果。

  
        
            
                Item ID
                List Price
                Amount
                Unit Cost
                Attribute
                Status
            
        
    

当用户点击一行的时候,我们开始一个编辑动作。

var lastIndex;
    $('#tt').datagrid({
        onClickRow:function(rowIndex){
            if (lastIndex != rowIndex){
                $('#tt').datagrid('endEdit', lastIndex);
                $('#tt').datagrid('beginEdit', rowIndex);
                setEditing(rowIndex);
            }
            lastIndex = rowIndex;
        }
    });

为了在一些列之间创建运算关系,我们应该得到当前的 editors,并绑定一些事件到它们上面。

   function setEditing(rowIndex){
        var editors = $('#tt').datagrid('getEditors', rowIndex);
        var priceEditor = editors[0];
        var amountEditor = editors[1];
        var costEditor = editors[2];
        priceEditor.target.bind('change', function(){
            calculate();
        });
        amountEditor.target.bind('change', function(){
            calculate();
        });
        function calculate(){
            var cost = priceEditor.target.val() * amountEditor.target.val();
            $(costEditor.target).numberbox('setValue',cost);
        }
    }
关注
打赏
1662376985
查看更多评论
立即登录/注册

微信扫码登录

0.1636s