다음 코드가 붙어 있습니다. 데이터 테이블에서 선택한 행 / 행의 열 값을 가져오고 싶었습니다. 이 코드를 사용했습니다
DataTable 코드 :
var table = $('#tableId').DataTable({
"ajax": {
"url": "Content",
"dataSrc": "",
data: {sectionUrl: "", siteUrl: siteurl}
},
"columns": [
// {"defaultContent": "<input type='checkbox' name='vehicle' id='checkID'>"},
{"data": "postIMAGE", "render": function (data) {
return '<img src=' + data + ' width="154" height="115"/>';
}},
{"data": "postTITLE"},
{"data": "postURL", "render": function (data) {
return '<a href=' + data + ' target="_blank"/>' + data + '</a>';
}},
{"data": "postSection"}
]
});
.
$('#tableId tbody').on('click', 'tr', function () {
$(this).toggleClass('selected');
});
$('#button').click(function () {
var selectedRows = table.rows('.selected').data();
var results = "";
for (i = 0; i < selectedRows.length; i++) {
alert();
}
});
나는 열의 값을 얻고 싶다
다음과 같이 개체의 값에 액세스 할 수 있습니다.
$('#button').click(function () {
var selectedRows = table.rows('.selected').data();
//if you are getting array of objects inside main object
alert(selectedRows[0].postTITLE);
alert(selectedRows[0].postURL);
// if you are getting just plain object you can access it as
alert(selectedRows.postTITLE);
alert(selectedRows.postURL);
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다