Я использую DataTable , чтобы преобразовать обычную таблицу в DataTable
В моей таблице есть AngularJS ng-if
, чтобы изменить положение столбца
Мой HTML-код
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th ng-if="pos-index == 0">Position</th> <!--pos-index = 0, render column here-->
<th>Office</th>
<th>Age</th>
<th ng-if="pos-index == 1">Position</th> <!--pos-index = 1, render column here-->
<th>Salary</th>
</tr>
</thead>
</table>
My JS
$scope['pos-index'] = 1;
var t = ('#example').DataTable({
columns: [
data: "name",
data: "office",
data: "age",
data: "salary"
//How to render Position column base on its pos-index?
]
});
Другие столбцы отображаются отлично, но я не знаю, как отобразить столбец Position. Я пытался создать 2 столбца позиции, как это
columns: [
data: "name",
data: "position"
data: "office",
data: "age",
data: "position"
data: "salary"
]
И сделал это
if ($scope['pos-index'] === 0) {
t.column(1).visible(true);
t.column(4).visible(false);
} else {
t.column(1).visible(false);
t.column(4).visible(true);
}
Но это не сработало.
Есть идеи для моего дела?