Item ID Product List Price Unit Cost Attribute Status
$(function(){ var lastIndex; $('#tt').datagrid({ toolbar:[{ text:'append', iconCls:'icon-add', handler:function(){ $('#tt').datagrid('endEdit', lastIndex); $('#tt').datagrid('appendRow',{ itemid:'', productid:'', listprice:'', unitprice:'', attr1:'', status:'P' }); lastIndex = $('#tt').datagrid('getRows').length-1; $('#tt').datagrid('selectRow', lastIndex); $('#tt').datagrid('beginEdit', lastIndex); } },'-',{ text:'delete', iconCls:'icon-remove', handler:function(){ var row = $('#tt').datagrid('getSelected'); if (row){ var index = $('#tt').datagrid('getRowIndex', row); $('#tt').datagrid('deleteRow', index); } } },'-',{ text:'GetChanges', iconCls:'icon-search', handler:function(){ var rows = $('#tt').datagrid('getChanges'); alert('changed rows: ' + rows.length + ' lines'); } }], onBeforeLoad:function(){ $(this).datagrid('rejectChanges'); }, onClickRow:function(rowIndex){ if (lastIndex != rowIndex){ $('#tt').datagrid('endEdit', lastIndex); $('#tt').datagrid('beginEdit', rowIndex); } lastIndex = rowIndex; } }); });