数据表列未向右对齐



我正在处理数据表,我已经成功创建了一个数据表,但面临着将数据对齐到某些列右侧的问题

代码段

var data=[
		  {
		    "amount": 518212,
		    "billdate": "2018-08-04",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 104801,
		    "billdate": "2018-08-04",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 138151,
		    "billdate": "2018-08-04",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 628358,
		    "billdate": "2018-08-05",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 115223,
		    "billdate": "2018-08-05",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 134107,
		    "billdate": "2018-08-05",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 177866,
		    "billdate": "2018-08-06",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 66095,
		    "billdate": "2018-08-06",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 284069,
		    "billdate": "2018-08-07",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 58789,
		    "billdate": "2018-08-07",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 67886,
		    "billdate": "2018-08-07",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 313128,
		    "billdate": "2018-08-08",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 59939,
		    "billdate": "2018-08-08",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 68558,
		    "billdate": "2018-08-08",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 321797,
		    "billdate": "2018-08-09",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 64431,
		    "billdate": "2018-08-09",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 57352,
		    "billdate": "2018-08-09",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 323556,
		    "billdate": "2018-08-10",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 58772,
		    "billdate": "2018-08-10",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 43722,
		    "billdate": "2018-08-10",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 464127,
		    "billdate": "2018-08-11",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 93110,
		    "billdate": "2018-08-11",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 62213,
		    "billdate": "2018-08-11",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 626772,
		    "billdate": "2018-08-12",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 126933,
		    "billdate": "2018-08-12",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 63119,
		    "billdate": "2018-08-12",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 167391,
		    "billdate": "2018-08-13",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 27110,
		    "billdate": "2018-08-13",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 275115,
		    "billdate": "2018-08-14",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 58633,
		    "billdate": "2018-08-14",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 37920,
		    "billdate": "2018-08-14",
		    "outlet": "KOLAR"
		  }
		];
		var columndef=[{title:"amount",data:"amount"},{title:"billdate",data:"billdate"},{title:"outlet",data:"outlet"}];
					$('#tbl').DataTable({
		      columns:columndef,
						data : data,
		        scrollY:        '30vh',
		        scrollCollapse: true,
		        paging:         true,
		        "columnDefs" : [ {
					"targets" : [0],
					  className : 'dt-body-right',
					"render" : function(data, type, row) {
						return Number(data).toLocaleString('en-IN', {
							maximumFractionDigits : 2,
						});
						
					}
		      
				}]
					
					});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.18/r-2.2.2/sc-1.5.0/datatables.min.css"/>
<link rel="stylesheet"
	href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.18/r-2.2.2/sc-1.5.0/datatables.min.js"></script>
<script
		src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<table id="tbl"></table>

我还为印度货币设置了逗号分隔符,这很好,但没有对齐。

我试图将第一列对齐,即向右对齐,但没有正确对齐,我不知道我遗漏了什么。

您做得很好,但没有包括所需的CDNLink

包括

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.19/css/jquery.dataTables.min.css" />

检查代码段

var data=[
		  {
		    "amount": 518212,
		    "billdate": "2018-08-04",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 104801,
		    "billdate": "2018-08-04",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 138151,
		    "billdate": "2018-08-04",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 628358,
		    "billdate": "2018-08-05",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 115223,
		    "billdate": "2018-08-05",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 134107,
		    "billdate": "2018-08-05",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 177866,
		    "billdate": "2018-08-06",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 66095,
		    "billdate": "2018-08-06",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 284069,
		    "billdate": "2018-08-07",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 58789,
		    "billdate": "2018-08-07",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 67886,
		    "billdate": "2018-08-07",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 313128,
		    "billdate": "2018-08-08",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 59939,
		    "billdate": "2018-08-08",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 68558,
		    "billdate": "2018-08-08",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 321797,
		    "billdate": "2018-08-09",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 64431,
		    "billdate": "2018-08-09",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 57352,
		    "billdate": "2018-08-09",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 323556,
		    "billdate": "2018-08-10",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 58772,
		    "billdate": "2018-08-10",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 43722,
		    "billdate": "2018-08-10",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 464127,
		    "billdate": "2018-08-11",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 93110,
		    "billdate": "2018-08-11",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 62213,
		    "billdate": "2018-08-11",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 626772,
		    "billdate": "2018-08-12",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 126933,
		    "billdate": "2018-08-12",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 63119,
		    "billdate": "2018-08-12",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 167391,
		    "billdate": "2018-08-13",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 27110,
		    "billdate": "2018-08-13",
		    "outlet": "KOLAR"
		  },
		  {
		    "amount": 275115,
		    "billdate": "2018-08-14",
		    "outlet": "JAYANAGAR"
		  },
		  {
		    "amount": 58633,
		    "billdate": "2018-08-14",
		    "outlet": "MALLESHWARAM"
		  },
		  {
		    "amount": 37920,
		    "billdate": "2018-08-14",
		    "outlet": "KOLAR"
		  }
		];
		var columndef=[{title:"amount",data:"amount"},{title:"billdate",data:"billdate"},{title:"outlet",data:"outlet"}];
					$('#tbl').DataTable({
		      columns:columndef,
						data : data,
		        scrollY:        '30vh',
		        scrollCollapse: true,
		        paging:         true,
		        "columnDefs" : [ {
					"targets" : [0],
					  className : 'dt-body-right',
					"render" : function(data, type, row) {
						return Number(data).toLocaleString('en-IN', {
							maximumFractionDigits : 2,
						});
						
					}
		      
				}]
					
					});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.18/r-2.2.2/sc-1.5.0/datatables.min.css"/>
<link rel="stylesheet"
	href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.19/css/jquery.dataTables.min.css" />
<link rel="stylesheet"
	href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.18/r-2.2.2/sc-1.5.0/datatables.min.js"></script>
<script
		src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<table id="tbl"></table>

最新更新