我想在列数大于10时修复数据表的列。
在数据表初始化期间,如何找出列数?
# finding the 1RM for any given day
def get_oneRepMax(data, compExercise):
oneRepMax = pd.DataFrame(columns = data.columns)
# define starting variables
currentDate = data.loc[0, 'Date']
currentExercise = data.loc[0, 'Exercise Name']
currentRM = data.loc[0, '1RM']
# iterate to find the largest for given date
for index, row in data.iterrows():
newDate = data.iloc[index,0]
newExercise = data.iloc[index,1]
newRM = data.loc[index, '1RM']
if (newExercise == compExercise):
if (currentRM < newRM) and (newDate == currentDate):
currentRM = newRM
newRow = data.loc[index, :]
# record 1RM for given date
elif (newDate > currentDate):
oneRepMax = oneRepMax.append(newRow)
# resetting values
currentDate = newDate
currentRM = 0
currentExercise = newExercise
return oneRepMax;
答案 0 :(得分:0)
您只需要在前<td>
中计算<tr>
的总长度。 (任何未应用colspan
的行)
$('#example thead th').length
将返回表中的列总数。
您需要为>10
应用条件,依此类推。
检查以下示例:
$(document).ready(function () {
var table = $('#example').DataTable({
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false,
fixedColumns: {
leftColumns: checkColumn()
}
});
});
function checkColumn() {
console.log($('#example thead th').length);
return $('#example thead th').length >= 10 ? 2 : 1;
}
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/fixedcolumns/3.2.6/css/fixedColumns.dataTables.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/fixedcolumns/3.2.6/js/dataTables.fixedColumns.min.js"></script>
<table id="example" class="stripe row-border order-column" style="width:100%">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th>Col 5</th>
<th>Col 6</th>
<th>Col 7</th>
<th>Col 8</th>
<th>Col 9</th>
<th>Col 10</th>
<th>Col 11</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger</td>
<td>Nixon</td>
<td>data 1.3</td>
<td>data 1.4</td>
<td>data 1.5</td>
<td>data 1.6</td>
<td>data 1.7</td>
<td>data 1.8</td>
<td>data 1.9</td>
<td>data 1.10</td>
<td>data 1.11</td>
</tr>
<tr>
<td>Garrett</td>
<td>Winters</td>
<td>data 2.3</td>
<td>data 2.4</td>
<td>data 2.5</td>
<td>data 2.6</td>
<td>data 2.7</td>
<td>data 2.8</td>
<td>data 2.9</td>
<td>data 2.10</td>
<td>data 2.11</td>
</tr>
<tr>
<td>Ashton</td>
<td>Cox</td>
<td>data 3.3</td>
<td>data 3.4</td>
<td>data 3.5</td>
<td>data 3.6</td>
<td>data 3.7</td>
<td>data 3.8</td>
<td>data 3.9</td>
<td>data 3.10</td>
<td>data 3.11</td>
</tr>
</tbody>
</table>
在上面的示例中,如果您想在内部创建更多代码进行验证等,则创建了一个函数checkColumn()
。
然后它将返回int
的值,该值将直接应用于leftColumns:checkColumn()