一:datagrid增删改查操作
1:查询
查询不过就是需要一些筛选条件,而datagrid的load方法,可以很好的支持
向后台提供需要的筛选条件
$("#dt").datagrid("load",{uername:'aaa'})
第二个参数就是需要的查询条件,是一个json对象
传对象的时候可以使用jquery插件把查询条件的表单序列化成json对象
不用自己去一个一个拼接参数
2:增删改
先使用toolbar给datagrid增加增删改查的功能条
toolbar: [
{ text: '增加', iconCls: "icon-add", handler: function () { } }, '-',
{ text: '删除', iconCls: "icon-remove", handler: function () { } }, '-',
{ text: '修改', iconCls: "icon-edit", handler: function () { } },'-',
{ text: '查询', iconCls: "icon-search", handler: function () { } }
]
二:获取datagrid中的editor嵌套对象
<th id="lineid" data-options="field:'LineId',width:130,
formatter:function(value,row){
return row.LineName;
},
editor:{
type:'combobox',
options:{
valueField:'LineId',
textField:'LineName',
url:'/PortList/GetLineAll2',
multiple:true,
editable:false
}
}">航线</th>
获取第1行的lineid中的嵌套对象
var ed = $('#dg').datagrid('getEditor', { index: 0 field: 'LineId' });
if (ed != null) {
var LineName = $(ed.target).combobox('getValues');
alert(LineName);
}
三:嵌套对应combobox设置默认值
<th data-options="field:'ServicePeopleId',width:80,
formatter:function(value,row){
return row.ServicePeopleName;
},
editor:{
type:'combobox',
options:{
valueField:'Id',
textField:'RealName',
url:'/xt/GetUser_DM',
editable:false,
onLoadSuccess:function()
{
var myvalue = $(this).combobox('getValue');
if(myvalue == '' || myvalue==null ){ //如果有值就不选择默认的,没有选择时才选择默认值
var data = $(this).combobox('getData');
$(this).combobox('select',data[0].Id);}
}
}
}">服务人员</th>
四:获取选中行的数据
var currentRow = $("#dg_gm").datagrid("getSelections");