EasyUI Forum
March 28, 2024, 09:50:45 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Calculate data grid cell when add new row  (Read 13396 times)
shivavalkyre
Newbie
*
Posts: 39


View Profile
« on: October 17, 2017, 02:01:20 AM »

Hi,
 i have some problem when try to calculate 2 cell, not in edit cell but for add new row in datagrid here my code:

Code:


<script>
$(function(){
var lastIndex;
$('#dg').datagrid({
onClickRow:function(rowIndex){
if (lastIndex != rowIndex){
$(this).datagrid('endEdit', lastIndex);
$(this).datagrid('beginEdit', rowIndex);
}
lastIndex = rowIndex;
},
onBeginEdit:function(rowIndex){
var editors = $('#dg').datagrid('getEditors', rowIndex);
var n1 = $(editors[2].target);
var n2 = $(editors[3].target);
var n3 = $(editors[4].target);
n1.add(n2).textbox({
onChange:function(){
var cost = n1.textbox('getValue')*n2.textbox('getValue');
n3.textbox('setValue',cost);
}
})
}
});
});
</script>

<table id="dg"  style="width:100%;height:250px" data-options="toolbar:'#toolbar', pagination:true, idField:'id', rownumbers:true, fitColumns:true, singleSelect:true">
        <thead>
            <tr>
                <th field="product"  width="50" editor="{type:'combogrid',options:{required:true,panelWidth:480,idField:'pcn',textField:'product',mode:'remote',url:'../control/get_product_price_join.php',columns: [[
{field:'pcn',title:'pcn',width:100},{field:'product',title:'product',width:250},{field:'unit',title:'unit',width:50},{field:'price',title:'price',width:70}

]],onSelect: onSelectGrid,
onShowPanel: onShowPanel,
onHidePanel: onHidePanel,}}">Product</th>
<th field="unit" width="30" editor="{type:'text',options:{required:false}}">Unit</th>
                <th field="qty" width="50" editor="{type:'numberbox',options:{precision:0}}">Qty</th>
                <th field="price" width="50"  editor="{type:'text'}">Price</th>
<th field="amount" width="50"  editor="{type:'text'}">Amount</th>
              
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onClick="javascript:$('#dg').edatagrid('addRow')">New</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onClick="javascript:$('#dg').edatagrid('destroyRow')">Destroy</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" plain="true" onClick="javascript:$('#dg').edatagrid('saveRow')">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onClick="javascript:$('#dg').edatagrid('cancelRow')">Cancel</a>
    </div>
    <script type="text/javascript">
        $(function(){
            $('#dg').edatagrid({
                saveUrl: '../control/save_quotation_detail.php',
                updateUrl: '../control/update_qoutation_detail.php',
                destroyUrl: '../control/delete_quotation_detail.php'
            });
        });



var cbg=null;
var tb=null;

function onSelectGrid(index,record) {
if(cbg) {
var cb = cbg;
var opts =cb.combogrid('options');
var grid = cb.combogrid('grid');
var row= grid.datagrid('getSelected');
// alert (row.price);
var dgs = $('#dg');
var index = dgs.datagrid('getRowIndex', dgs.datagrid('getSelected'));
// var index = $('#dgs').datagrid('getSelected');
alert (index);
alert (row.price);

var editors = dgs.datagrid('getEditors', index);
$(editors[1].target).val(row.unit);
$(editors[3].target).val(row.price);
$(editors[4].target).val(row.price);


}
}




function onShowPanel() {
cbg = $(this);

}
function onHidePanel() {
cbg = null;
}


Anyone can help my problem please?

Best Regards

Shiva
« Last Edit: October 17, 2017, 02:03:29 AM by shivavalkyre » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: October 18, 2017, 03:00:24 AM »

Please refer to this example http://code.reloado.com/ufawel4/edit#preview
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!