2013-02-06 153 views
0

Im使用jqgrid的数据网格。jqgrid编辑删除按钮行

我想编辑和删除每一行使用编辑按钮和删除按钮,而不是点击行。 这里是jQuery代码:

$(function(){ 
var lastsel2 
$("#list").jqGrid({      
url:'example.php', 
datatype: 'xml', 
mtype: 'GET', 
colNames:['id','name', 'status'], 
colModel :[ 
{name:'id', index:'id', width:155}, 
{name:'name', index:'name', width:190, editable: true}, 
{name:'status', index:'status', width:180, align:'right', editable: true},       
],  

onSelectRow: function(id){ 
//if(appid && appid!==lastsel2){ 
if (id && id !== lastsel2){ 
jQuery('#list').restoreRow(lastsel2); 
jQuery('#list').editRow(id,true); 
lastsel2=id; 
}      
}, 
editurl: "example.php", 
pager: '#pager', 
rowNum:10, 
rowList:[10,20,30], 
sortname: 'appid', 
sortorder: 'desc', 
viewrecords: true, 
gridview: true, 
caption: 'My first grid' 
}); 
}); 

HTML代码

<table id="list"><tr><td> </td></tr></table> 
<div id="pager"></div> 

enter image description here IM附加图像,

回答

0

我做了什么:

  • 每一行都将包含动作
  • 动作可以包含任何操作,例如:编辑或删除。

这是我的代码

jQuery("#list4"). 
     jqGrid(
      { datatype: "local" 
      , height: 250 
      , colNames:['Action','Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'] 
      , colModel: 
       [ {name:'action', width:30 } 
       , {name:'id',index:'id', width:60, sorttype:"int"} 
       , {name:'invdate',index:'invdate', width:90, sorttype:"date",editable:true} 
       , {name:'name',index:'name', width:100,editable:true} 
       , {name:'amount',index:'amount', width:80, align:"right",sorttype:"float",editable:true} 
       , {name:'tax',index:'tax', width:80, align:"right",sorttype:"float",editable:true} 
       , {name:'total',index:'total', width:80,align:"right",sorttype:"float",editable:true} 
       , {name:'note',index:'note', width:150, sortable:false,editable:true} 
       ] 

...

And populate data, it should contain such as: 
action:"<a title='save' class='ui-pg-div ui-pg-button ui-corner-all' style='display:block; border:0px none' href='javascript:saveInLineRow(\"list4\")'><span class='ui-icon ui-icon-plus'></span></a>"