• datagrid实现单行的选择、取消


    <html>
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    	<meta name="keywords" content="jquery,ui,easy,easyui,web">
    	<meta name="description" content="easyui help you build your web page easily!">
    	<title>jQuery EasyUI Demo</title>
    	<link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/default/easyui.css">
    	<link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/icon.css">
    	<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
    	<script type="text/javascript" src="http://www.jeasyui.net/Public/js/easyui/jquery.easyui.min.js"></script>
    	<script>
    		function getSelected(){
    			var row = $('#tt').datagrid('getSelected');
    			if (row){
    				alert('Item ID:'+row.itemid+"
    Price:"+row.listprice);
    			}
    		}
    		function getSelections(){
    			var ids = [];
    			var rows = $('#tt').datagrid('getSelections');
    			for(var i=0; i<rows.length; i++){
    				ids.push(rows[i].itemid);
    			}
    			alert(ids.join('
    '));
    		}
            
            function upRow(){
                var row = $('#tt').datagrid('getSelected');
                var rowindex = $('#tt').datagrid('getRowIndex',row);
                //alert(rowindex);
                if(rowindex === 0) {return; }
                $('#tt').datagrid('insertRow',{index:rowindex-1,row});
                $('#tt').datagrid('deleteRow',rowindex+1);
            }
            function allRows(){
                var rows = $('#tt').datagrid('getRows');
                alert(rows.length);
                for(var i=0; i<rows.length; i++){
                    alert(rows[i].itemid);
                }
            }
            
            //实现选择单行,取消单行
            $(function(){
                $("#tt").datagrid({
                    onBeforeSelect: function(index,row){
                        var row =$('#tt').datagrid('getSelected');
                        var curRowindex = $('#tt').datagrid('getRowIndex',row);
                        alert("当前selected row =" + curRowindex);
                        if(curRowindex != index) {return true;}
                        else{ $('#tt').datagrid('unselectRow',index); return false;}
                    }
                });
            });
    	</script>
    </head>
    <body>
    	<h1>DataGrid</h1>
    	<div style="margin-bottom:20px">
    		<a href="#" onclick="getSelected()">GetSelected</a>
    		<a href="#" onclick="getSelections()">GetSelections</a>
            <a href="#" onclick="upRow()">upRow</a>
            <a href="#" onclick="allRows()">all rows</a>
    	</div>
    	<table id="tt" class="easyui-datagrid" style="600px;height:250px"
    			url="data/datagrid_data.json"
                data-options="singleSelect:true"
    			title="Load Data" iconCls="icon-save" fitColumns="true">
    		<thead>
    			<tr>
    				<th field="itemid" width="80">Item ID</th>
    				<th field="productid" width="80">Product ID</th>
    				<th field="listprice" width="80" align="right">List Price</th>
    				<th field="unitcost" width="80" align="right">Unit Cost</th>
    				<th field="attr1" width="150">Attribute</th>
    				<th field="status" width="60" align="center">Stauts</th>
    			</tr>
    		</thead>
    	</table>
    </body>
    </html>
    
  • 相关阅读:
    elementui 修改合计行样式
    C# 导出Excel NPOI 修改指定单元格的样式 或者行样式
    向基于语义模型的操作集成的演变
    在制造业的工业2.0中应用MOM系统
    制造运营管理 (MOM) 的工作流驱动方法
    语义模型在智能工业运营中的作用
    定义运营系统架构
    在离散混合制造环境中应用制造运营模型
    面试官:如果存取IP地址,用什么数据类型比较好 (C#版本)
    使用WtmPlus低代码平台提高生产力
  • 原文地址:https://www.cnblogs.com/zhao1949/p/6109799.html
Copyright © 2020-2023  润新知