toolbar: [{ text: '添加', iconCls: 'icon-add', handler: function () { var row = $('#ss').datagrid('getSelected'); if (row) { var index = $('#ss').datagrid('getRowIndex', row); $('#ss').datagrid('insertRow', index); } } }, '-', { text: '编辑', iconCls: 'icon-remove', handler: function () { var row = $('#ss').datagrid('getSelected'); if (row) { var index = $('#ss').datagrid('getRowIndex', row); $('#ss').datagrid('editRow', index); } } }, '-', { text: '删除', iconCls: 'icon-remove', handler: function () { var row = $('#ss').datagrid('getSelected'); if (row) { var index = $('#ss').datagrid('getRowIndex', row); $('#ss').datagrid('deleteRow', index); } } }, '-', { text: '保存', iconCls: 'icon-save', handler: function () { $('#ss').datagrid('acceptChanges'); } }, '-', { text: '重置', iconCls: 'icon-undo', handler: function () { $('#ss').datagrid('rejectChanges'); } }], onBeforeLoad: function () { $(this).datagrid('rejectChanges'); }, onClickRow: function (rowIndex) { if (lastIndex != rowIndex) { $('#ss').datagrid('endEdit', lastIndex); $('#ss').datagrid('beginEdit', rowIndex); } lastIndex = rowIndex; }
{ text: '添加', iconCls: 'icon-add', handler: function() { $('#dg').datagrid('insertRow', { index: 1, row: { code: '', name: '', price: '' } }) } }
添加應該像這樣,塞空資料
另外
$('#ss').datagrid('editRow', index);,有這東西??
但是这样只是加了一个空白行啊
@昕薇の:
添加不就是添加空白行
没看见你写的点击事件或者跳转链接呀
<script type="text/javascript"> $('#grid').datagrid({ columns: [[ { field: 'Id', title: 'ID', width: 10, checkbox: true }, { field: 'Sorts', title: '排序', width: 20, align: 'center' }, { field: 'Title', title: '名称', width: 20, align: 'center' }, { field: 'Url', title: '链接', width: 20, align: 'center' } ]], toolbar: [ '-', { id: 'btnAddSelections', text: '添加', iconCls: 'icon-add', handler: function () { window.location = "LinkAdd.aspx?id=0"; } }, '-', { id: 'btnEdit', text: '修改', iconCls: 'icon-edit', handler: function () { // deleteData(); var row = $('#grid').datagrid("getSelections"); if ($(row).length < 1 || $(row).length > 1) { alert("请选择要修改的记录,只能选取单行!"); return; } else { window.location = "LinkAdd.aspx?id=" + row[0].Id; } } }, '-', { id: 'btnDel', text: '删除', iconCls: 'icon-no', handler: function () { // deleteData(); var row = $('#grid').datagrid("getSelections"); if (confirm("您确定要删除吗?")) { var where = "id in ("; for (var i = 0; i < row.length; i++) { where += row[i].Id + ","; } where += "0)"; $.get('../../Handle/Handler.ashx?operate=delete&tablename=Link', { str: where }, function (data) { alert(data); if (data.indexOf("成功") > -1) { $('#grid').datagrid('reload'); } }); } } } ] }); //------------------ </script>