bootstrap表格(带合计行)

bootstrap表格(带合计行)
showFooter该属性就是展示合计行的
onPreBody该属性是在换页时将之前的对应的合计行清空值,否则翻页时合计值会累加,不断增加

function inittable3(bm,kj,tPoint) {
	var rshj=0;
	var ahj=0;
	var bhj=0;
	var chj=0;
	var dhj=0;
	var ehj=0;
	var fhj=0;
	var ghj=0;
	
	$('#part6').bootstrapTable({
		url: basePath + '/zljgData/data20195075?goal='+bm+'&tPoint='+tPoint+'&kj='+kj,
		method: 'POST',
		striped: true,
		pagination: true,
		paginationLoop: false,
		sidePagination: 'client',
		queryParams: function (params) {
			return getParams(params);
		},
		pageNumber: 1,
		pageSize: 15,
		showFooter: true,
	    columns: [[
	    	{field: 'YEARMONTHID', title: '序号', align: 'center',rowspan:'2',
	    		formatter: function (value, row, index) {
					return index+1;
				},
	    		footerFormatter: function (value) { return "合计"; }},
	    	{field: 'BM_NAME', title: '部门', align: 'center', rowspan:'2'},
	    	{field: 'RS',title: '人数', align: 'center',rowspan:'2',
	    		formatter: function(value, row, index){
	    			rshj+=value;
	    			return value;
	            }, 
	    		footerFormatter: function (value) { //底部合计
	    			return rshj;
	    	    }},
	    	{title: '年龄段人数', align: 'center',colspan:'7' },
	    	{title: '年龄段占比', align: 'center' ,colspan:'7'},
	    ],[
            {field: 'A', title: '29及以下', align: 'center',rowspan:'1',
            	formatter: function(value, row, index){
	    			rshj+=value;
	    			return value;
	            }, 
	    		footerFormatter: function (value) { //底部合计
	    			return rshj;
	    	    }},
            {field: 'B', title: '30-34', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			bhj+=value;
		    			return value;
		            }, 
		    		footerFormatter: function (value) { //底部合计
		    			return bhj;
		    	    }},
            {field: 'C', title: '35-39', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			chj+=value;
		    			return value;
		            }, 
		    		footerFormatter: function (value) { //底部合计
		    			return chj;
		    	    }},
            {field: 'D', title: '40-44', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			dhj+=value;
		    			return value;
		            }, 
		    		footerFormatter: function (value) { //底部合计
		    			return dhj;
		    	    }},
            {field: 'E', title: '45-49', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			ehj+=value;
		    			return value;
		            }, 
		    		footerFormatter: function (value) { //底部合计
		    			return ehj;
		    	    }},
            {field: 'F', title: '50-54', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			fhj+=value;
		    			return value;
		            }, 
		    		footerFormatter: function (value) { //底部合计
		    			return fhj;
		    	    }},
            {field: 'G', title: '55及以上', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			ghj+=value;
		    			return value;
		            }, 
		    		footerFormatter: function (value) { //底部合计
		    			return ghj;
		    	    }},
            {field: 'ZB_A', title: '29及以下', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			return formatNumber(value*100,1)+'%';
		            },footerFormatter: function (value) { //底部合计
		    			return formatNumber(ahj/rshj*100,1)+'%' ;
		    	    }},
            {field: 'ZB_B', title: '30-34', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			return formatNumber(value*100,1)+'%';
		            },footerFormatter: function (value) { //底部合计
		    			return formatNumber(bhj/rshj*100,1)+'%' ;
		    	    }},
            {field: 'ZB_C', title: '35-39', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			return formatNumber(value*100,1)+'%';
		            },footerFormatter: function (value) { //底部合计
		    			return formatNumber(chj/rshj*100,1)+'%' ;
		    	    }},
            {field: 'ZB_D', title: '40-44', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			return formatNumber(value*100,1)+'%';
		            },footerFormatter: function (value) { //底部合计
		    			return formatNumber(dhj/rshj*100,1)+'%' ;
		    	    }},
            {field: 'ZB_E', title: '45-49', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			return formatNumber(value*100,1)+'%';
		            },footerFormatter: function (value) { //底部合计
		    			return formatNumber(ehj/rshj*100,1)+'%' ;
		    	    }},
            {field: 'ZB_F', title: '50-54', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			return formatNumber(value*100,1)+'%';
		            },footerFormatter: function (value) { //底部合计
		    			return formatNumber(fhj/rshj*100,1)+'%' ;
		    	    }},
            {field: 'ZB_G', title: '55及以上', align: 'center',rowspan:'1',
	    	    	formatter: function(value, row, index){
		    			return formatNumber(value*100,1)+'%';
		            },footerFormatter: function (value) { //底部合计
		    			return formatNumber(ghj/rshj*100,1)+'%' ;
		    	    }},
	       ]],
			onPreBody:function(data){
	    		 rshj = 0;
	    		 ahj =0;
	    		 bhj=0;
	    		 chj=0;
	    		 dhj=0;
	    		 ehj=0;
	    		 fhj=0;
	    		 ghj=0;
	       },
	});
}

你可能感兴趣的:(bootstrap表格(带合计行))