日期:2014-05-16 浏览次数:20368 次
<script> function productFormatter(value){ for(var i=0; i<products.length; i++){ if (products[i].work == value) return products[i].name; } return value; } $(function(){ var lastIndex; $('#tt').datagrid({ toolbar:[{ text:'新增', iconCls:'icon-add', handler:function(){ $('#tt').datagrid('endEdit', lastIndex); $('#tt').datagrid('appendRow',{ itemid:'', work:'', salary:'', unitprice:'', ename:'', status:'P' }); lastIndex = $('#tt').datagrid('getRows').length-1; $('#tt').datagrid('selectRow', lastIndex); $('#tt').datagrid('beginEdit', lastIndex); } },'-',{ text:'删除', iconCls:'icon-remove', handler:function(){ var row = $('#tt').datagrid('getSelected'); if (row){ var index = $('#tt').datagrid('getRowIndex', row); $('#tt').datagrid('deleteRow', index); } } },'-',{ text:'保存', iconCls:'icon-save', handler:function(){ $('#tt').datagrid('acceptChanges'); } },'-',{ text:'撤销全部', iconCls:'icon-undo', handler:function(){ $('#tt').datagrid('rejectChanges'); } },'-',{ text:'查看变更', iconCls:'icon-search', handler:function(){ var rows = $('#tt').datagrid('getChanges'); alert('变更行数: ' + rows.length + ' 行!'); } }], onBeforeLoad:function(){ $(this).datagrid('rejectChanges'); }, onClickRow:function(rowIndex){ if (lastIndex != rowIndex){ $('#tt').datagrid('endEdit', lastIndex); $('#tt').datagrid('beginEdit', rowIndex); } lastIndex = rowIndex; } }); }); </script>