에 따라 says on the tin에 따라 선택되지 않는 경우 Datatables가 "데이터 다시로드를 통한 행 선택을 유지할 수 있어야합니다." 하지만 아약스의 데이터를 사용할 때는 제대로 작동하지 않습니다. Datatables.js 선택한 행이 ajax.reload()
setInterval(function() {
oTable.ajax.reload();
}
그러나 선택된 행 : 내가 처음에 테이블 5 초마다 새로 고침이 사용 위의 참조의 지시에 따라
oTable = $('#fileList').DataTable({
select: true,
"ajax": {
"url": "./data.php",
"type": "GET"
},
rowId: 'Index',
"createdRow": function (row, data, dataIndex) {
$(row).addClass(data[2]); //set formatting from data[2]
}
});
: 여기
내가 내 테이블을 만드는 방법 5 초마다 선택을 취소합니다. 그래서 더 명시되는 시도 : 배열 내로 선택된 행을 로딩하여 setInterval 함수 내에 그들을 재 선택 :
setInterval(function() {
var selectedRows = [];
//put all the selected rows into an array:
sel = oTable.rows('.selected').every(function (rowIdx) {
selectedRows.push(rowIdx);
});
oTable.ajax.reload();
console.log(selectedRows);
//select all the rows from the array
for (var i = 0; i < selectedRows.length; i++) {
console.log("selecting ",selectedRows[i]);
oTable.rows(selectedRows[i]).select();
}
}, 5000)
});
를 콘솔 I (이 예에서 세 번째 행), 선택된 행이 있어도 참조 :
Array [ 2 ]
selecting 2
예상대로이지만 행을 다시 선택하지 않았습니다. 콘솔에 oTable.rows(2).select();
을 입력하면 세 번째 행을 선택하지만 setInterval
블록에서는 작동하지 않습니다.
나는 그것이 rowID 속성과 관련이 있다고 생각합니다. 나는이 같은 HTML 테이블을 정의했습니다 :
<table id="fileList" class="display">
<thead>
<tr>
<th>Index</th>
<th>Status</th>
<th>Owner</th>
</tr>
</thead>
</table>
및 데이터는 첫 번째 항목의 인덱스입니다
{"data":[["1", "foo", "bar"], ["2", "fuz", "baz"]}
같은 배열을 반환하는 PHP 스크립트에서 비롯됩니다.
감사합니다. 연관 배열을 사용하려면 Datatable 객체를 만들 때 열을 지정해야하는 것처럼 보입니다. 서버 측의 연관 배열로 변경하고 여전히 숫자 인덱스로 데이터에 액세스하려고하면 데이터가 손상됩니다. – stib