Bootrap风格(父子)表格,基于ajax请求获取数据

基于bootstrap风格的父子表格效果实现使用bootstrap-table

data.json
{
    "total": 11,
    "rows": [
        {
            "id": 0,
            "name": "Item 0",
            "price": "$0"
        },
        {
            "id": 1,
            "name": "Item 1",
            "price": "$1"
        },
        {
            "id": 2,
            "name": "Item 2",
            "price": "$2"
        },
        {
            "id": 3,
            "name": "Item 3",
            "price": "$3"
        },
        {
            "id": 4,
            "name": "Item 4",
            "price": "$4"
        },
        {
            "id": 5,
            "name": "Item 5",
            "price": "$5"
        },
        {
            "id": 6,
            "name": "Item 6",
            "price": "$6"
        },
        {
            "id": 7,
            "name": "Item 7",
            "price": "$7"
        },
        {
            "id": 8,
            "name": "Item 8",
            "price": "$8"
        },
        {
            "id": 9,
            "name": "Item 9",
            "price": "$9"
        },
        {
            "id": 10,
            "name": "Item 10",
            "price": "$10"
        }
    ]
}
demo.jsp
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="/TestDemo/assets/bootstrap/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="/TestDemo/assets/bootstrap/css/bootstrap-table.css" />
<script src="/TestDemo/assets/bootstrap/js/jquery-3.0.0.min.js" ></script>
<script src="/TestDemo/assets/bootstrap/js/bootstrap.min.js" ></script>
<script src="/TestDemo/assets/bootstrap/js/bootstrap-table.js" ></script>
<title>Insert title here</title>
</head>
<body>
	<table id="table-javascript" ></table>
	<button id="choose" >选择数据</button>
</body>
<script type="text/javascript">
$(function(){
	var detail;
	var queryUrl ="http://localhost:8080/TestDemo/json/data.json"
	    var table= $('#table-javascript').bootstrapTable({
	    	method:'get',
	    	url:queryUrl,
	    	columns:[{
	    		checkbox: true 
	    	},{
	    		field:'id',
	    		title:'主键'
	    	},{
	    		field:'name',
	    		title:'名称'
	    	},{
	    		field:'price',
	    		title:'价格',
	    		formatter:function(value,row,rowIndex){
	    			//return value+"%";
	    			return "<input type='text' value='"+value+"' />%";
	    		}
	    	},{
	    		title:'操作',
	    		formatter:function(value,row,rowIndex){
	    			//console.log(row);
	    			return '<a>删除</a>';
	    		}
	    	}],
	    	sidePagination: "server",
	    	  editable:true,
	    	 //search: false,
	    	 //striped: true
	    	 //pagination: true,
	    	 
            // singleSelect: false

             pageSize: 50,

             //pageList: [10, 50, 100, 200, 500]
             detailView:true,
             onExpandRow:function(index, row, $detail){
            	 detail=$detail;
            	 children($detail);
             }
	    })
	    
           var children=function($detail){
        	   		$($detail.html('<table></table>').find('table')).bootstrapTable({
            		  url:'http://localhost:8080/TestDemo/json/data.json',
            		  method:'get',
            		 //queryParams:{},
            		// detailView:true,
            		  clickToSelect: true,
            		  columns:[{
            			  checkbox: true 
            		  },{
            	    		field:'id',
            	    		title:'主键'
            	    	},{
            	    		field:'name',
            	    		title:'名称'
            	    	},{
            	    		field:'price',
            	    		title:'价格'
            	    	}],
            	    	sidePagination: "server"
            		 
          })
        }
	    $("#choose").click(function(){
	    	// var ss=new children(detail); 
	    	 var selectContent = table.bootstrapTable('getSelections'); 
	    	 if(typeof(selectContent) == 'undefined') { 
	    		 alert("请选择数据");
	    	 }else{
	    		 //JSON.stringify(selectContent);
	    		 var arr=jQuery.makeArray(selectContent)
	    		/* $.each(selectContent,function(i,n){
	    			 console.log(i+"_"+n);
	    		}) */
	    		console.log(arr);
	    	 }
	    })
})
</script>
</html>

 

转载于:https://my.oschina.net/dxlmi/blog/1573125

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值