EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jaimi on October 07, 2016, 02:43:17 AM



Title: calcualte numberbox-values in a datagrid
Post by: jaimi on October 07, 2016, 02:43:17 AM
In your tutorial give the following sample:
Code:
$('#tt').datagrid({
    onClickRow:function(rowIndex){
        if (lastIndex != rowIndex){
            $(this).datagrid('endEdit', lastIndex);
            $(this).datagrid('beginEdit', rowIndex);
        }
        lastIndex = rowIndex;
    },
    onBeginEdit:function(rowIndex){
        var editors = $('#tt').datagrid('getEditors', rowIndex);
        var n1 = $(editors[0].target);
        var n2 = $(editors[1].target);
        var n3 = $(editors[2].target);
        n1.add(n2).numberbox({
            onChange:function(){
                var cost = n1.numberbox('getValue')*n2.numberbox('getValue');
                n3.numberbox('setValue',cost);
            }
        })
    }
});

As I understand you walk through the array of all editors within the row an assign them to the names n1,n2,...
If I don't want / need all existing editors for my calculation I would have the risk of corruption of the calculation if the order of fields changes.
Is it possible to address the field-editor by name or similar?


Title: Re: calcualte numberbox-values in a datagrid
Post by: stworthy on October 07, 2016, 08:06:00 PM
You can call 'getEditor' method with 'index' and 'field' parameter values to get the specified editor on datagrid row.
Code:
var ed = $(this).datagrid('getEditor', {index: index, field: 'listprice'});
var val = $(ed.target).numberbox('getValue');
console.log(val);


Title: Re: calcualte numberbox-values in a datagrid
Post by: jaimi on October 08, 2016, 01:05:55 AM
How would I put this in the onBeginEdit function?
Which function would be appropiate?