Title: Calculate data grid cell when add new row
Post by: shivavalkyre 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:
<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
Title: Re: Calculate data grid cell when add new row
Post by: stworthy on October 18, 2017, 03:00:24 AM
Please refer to this example http://code.reloado.com/ufawel4/edit#preview
|