当前位置: 代码迷 >> Web前端 >> jquery easyui datagrid的增多,修改,删除
  详细解决方案

jquery easyui datagrid的增多,修改,删除

热度:713   发布时间:2012-10-19 16:53:37.0
jquery easyui datagrid的增加,修改,删除

?

<link rel="stylesheet" type="text/css" href="../../script/themes/default/easyui.css" />  
    <link rel="stylesheet" type="text/css" href="../../script/themes/icon.css" />  
    <script type="text/javascript" src="../../script/jquery-1.4.2.min.js" </script>  
    <script type="text/javascript" src="../../script/jquery.easyui.min.js" </script>  
    <script type="text/javascript" src="../../script/locale/easyui-lang-zh_CN.js" mce_src="script/locale/easyui-lang-zh_CN.js"></script>  

js:

?

<script type="text/javascript"><!--  
        $(function(){  
            $('#tt').datagrid({  
                width:810,  
                height:400,  
                idField:'xsbh',  
                url:'studentHandler.ashx',  
                singleSelect:true,  
                columns:[[  
                   {field:'xsbh',title:'编号',width:80},  
                  {field:'UserName',title:'姓名',width:100},  
                  {field:'Sex',title:'性别',width:30},  
                  {field:'SchoolYear',title:'年份',width:50},  
                  {field:'opt',title:'操作',width:100,align:'center',  
                    formatter:function(value,rec,index){  
                        var s = '<a href="#" mce_href="#" onclick="view(\''+ rec.xsbh + '\')">查看</a> ';  
                        var e = '<a href="#" mce_href="#" onclick="edit(\''+ rec.xsbh + '\')">编辑</a> ';  
                        var d = '<a href="#" mce_href="#" onclick="del(\''+ index +'\')">删除</a> ';  
                        return s+e+d;  
                    }  
                  }  
                ]],  
                toolbar:[{  
                    text:'增加',iconCls:'icon-add',handler:function(){  
                        window.location.href='StuAdd.aspx';  
                    }  
                },  
                {text:'导入',iconCls:'icon-add',handler:function(){  
                    window.location.href='StuImport.aspx'  
                    }  
                },  
                {text:'查找',iconCls:'icon-search'}  
                ],  
               pagination:true  
            });  
        })  
          
          function view(bh)  //转到查看页面  
            {  
                window.location.href='StuView.aspx?id='+bh+'&page=stu';  
//              var row = $('#tt').datagrid('getSelected');  
//               if(row)  
//               {  
//                  alert(row.xsbh);  
//               }  
            }  
          function edit(bh)  //转到编辑页面  
          {  
                window.location.href='StuEdit.aspx?id='+bh;  
          }  
            
          function del(index){  //删除操作  
            $.messager.confirm('确认','确认删除?',function(row){  
                if(row){  
                    var selectedRow = $('#tt').datagrid('getSelected');  //获取选中行  
                    $.ajax({  
                        url:'delHandler.ashx?id='+selectedRow.xsbh+'&type=stu',    
//加了个type,作用是以后不管什么删除,都可以转到这个ashx中处理  
                        success:function(){alert('删除成功');}  
                    });  
                    $('#tt').datagrid('deleteRow',index);  
                }  
            })  
          }  
      
// --></script>  
  相关解决方案