easyUI-datagrid根據id進行回顯選中對應行

頁面代碼:

 

 

js代碼:


	$('#pro').click(function(){
		$('#goodsDialog').dialog('open');
		
		
				//獲取需要選中的記錄ID
				var refId =$("#refId").val();
			    
			    
			    //獲取數據列表中的所有數據
			    var rows = $("#gd_dataGrid").datagrid("getRows");
			    //循環數據找出列表中ID和需要選中數據的ID相等的數據並選中
			    for(var i=0;i<rows.length;i++){
			      var rowId = rows[i].id;
			      
			        if(rowId==refId){
			          var index = $("#gd_dataGrid").datagrid("getRowIndex",rows[i])
			          $("#gd_dataGrid").datagrid("selectRow",index);
			        }
			    }
			
		
	});
	
	$('#shop').click(function(){
		$('#shopsDialog').dialog('open');
		//獲取需要選中的記錄ID
				var refId =$("#refId").val();
			    
			    //獲取數據列表中的所有數據
			    var rows = $("#shop_dataGrid").datagrid("getRows");
			    //循環數據找出列表中ID和需要選中數據的ID相等的數據並選中
			    for(var i=0;i<rows.length;i++){
			      var rowId = rows[i].id;
			      
			        if(rowId==refId){
			          var index = $("#shop_dataGrid").datagrid("getRowIndex",rows[i])
			          $("#shop_dataGrid").datagrid("selectRow",index);
			        }
			    }
		
	});
	
	$("#dataType").change(function(){
        var dataType = $(this).val();
        $("#dataPrdDiv").hide();
        $("#dataShopDiv").hide();
        if (dataType == 1) {
        	$("#dataPrdDiv").show();
        } else if (dataType == 2) {
        	$("#dataShopDiv").show();
        }
        
    });

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章