?最主要的easyCrud.js代码如下:
$(function(){ ?$('#ff').hide(); ?$('#tt').datagrid({ ????title:'datagrid增删查该小例子', ????iconCls:'icon-save', ????width:500, ????height:350, ????//pageSize:5, ????pageList:[5,10,15,20], ????nowrap:false, ????striped: true, ????collapsible:true, ????url:'easyAction.action', ????loadMsg:'数据装载中......', ????sortName:'code', ????sortOrder:'desc', ????remoteSort:false, ????frozenColumns:[[ ?????{field:'ck',checkbox:true} ????]], ????columns:[[ ?????{title:'学号',field:'id',width:'50',rowspan:2,align:'center'}, ?????{title:'姓名',field:'name',width:'60',rowspan:2,align:'center'}, ?????{title:'性别',field:'sex',width:'50',rowspan:2,align:'center'}, ?????{title:'年龄',field:'age',width:'50',rowspan:2,align:'center'}, ?????{title:'出生日期',field:'birthday',width:'120',rowspan:2,align:'center'}, ?????{title:'班级',field:'className',width:'100',rowspan:2,align:'center'} ????]], ????pagination:true, ????rownumbers:true, ????toolbar:[{ ????? text:'全部', ????? iconCls:'icon-ok', ????? handler:function(){ ????? ?$('#tt').datagrid({url:'easyAction.action'}); ????? } ?????},'-',{ ????? text:'添加', ????? iconCls:'icon-add', ????? handler:function(){$('#add').window('open'); ??????$('#ff').show(); ??????$('#ff').form('clear'); ????? ?$('#ff').appendTo('#aa');} ?????},'-',{ ?????? text:'修改', ?????? iconCls:'icon-edit', ?????? handler:getSelect ?????},'-',{ ?????? text:'删除', ?????? iconCls:'icon-remove', ?????? handler:del ?????},'-',{ ?????? text:'查询', ?????? iconCls:'icon-search', ?????? handler:function(){ ?????? ?$('#query').window('open'); ?????? ? ?????? } ?????} ????] ???}); ???displayMsg(); ??}); ??function displayMsg(){ ???$('#tt').datagrid('getPager').pagination({displayMsg:'当前显示从{from}到{to}共{total}记录'}); ??} ??function close1(){ ???$('#add').window('close'); ??} ??function close2(){ ???$('#edit').window('close'); ??} ??function add(){ ??? $('#ff').form('submit',{ ????url: 'easyAdd.action', ????onSubmit:function(){ return $('#ff').form('validate');}, ???? ??success:function(){ ????? ?? close1(); ???? ?? } ???}); ???$.messager.alert('add','添加信息成功!!!','info',function(){ ????$('#tt').datagrid({ ?????url:'easyAction.action', ?????loadMsg:'更新数据中......' ????}); ????displayMsg(); ???}); ??} ??var id; ??function getSelect(){ ???var select = $('#tt').datagrid('getSelected'); ???if(select){ ????$('#edit').window('open'); ????$('#ff').show(); ????$('#ff').appendTo('#ee'); ????$('#name').val(select.name); ????$('#age').val(select.age); ????$('#sex').val(select.sex); ????$('#birthday').val(select.birthday); ????$('#className').val(select.className); ????id = select.id; ???}else{ ????$.messager.alert('warning','请选择一行数据','warning'); ???} ??} ??function edit(){ ??? $('#ff').form('submit',{ ????url: 'easyUpdate.action?id='+id, ????onSubmit:function(){ return $('#ff').form('validate');}, ???? ??success:function(){ ????? ?? $.messager.alert('edit','修改信息成功!!!','info'); ????? ?? close2(); ???? ?? } ???}); ???$('#tt').datagrid({ ????url:'easyAction.action', ????loadMsg:'更新数据......' ???}); ??? ??} ??function del(){ ???var selected = $('#tt').datagrid('getSelected'); ???if(selected){ ????$.messager.confirm('warning','确认删除么?',function(id){ ????if(id){ ?????id = selected.id; ?????$.ajax({ ????????? ???type:"POST", ???????? ???url:"easyDel.action", ????????? ???data:"id="+id, ???????? ???dataType:"xml", ???????? ???success:function callback(){} ??????? ??}); ???? $('#tt').datagrid('reload'); ????} ???}); ???}else{ ????$.messager.alert('warning','请选择一行数据','warning'); ???} ??} ??function query(){ ??var queryParams = $('#tt').datagrid('options').queryParams; ??queryParams.queryWord = $('#qq').val(); ??$('#tt').datagrid({ ???url:'easyQuery.action' ??}); ??displayMsg(); ??$('#query').window('close'); ? }
??
?
|