我不知道,如果它是你與數據表工作以同樣的方式,我想你想它的點擊,而不是在負載,但這裏的作品我使用的代碼:
要注意:
{ "bSortable": false, "bSearchable": false, "bVisible": false, "aTargets": [ 9 ] },
定位欄#9,no列上的排序,不可見。
示例代碼如下:
var table_data = $('#open_datatable').dataTable({
"aoColumns": [
{ "sTitle": "", "sClass": "datatable-tiny datatable-center", "bSortable": false }
,{ "sTitle": "ID", "sClass": "datatable-small" }
,{ "sTitle": "Date", "sClass": "datatable-small" }
,{ "sTitle": "Part Number" , "sClass": "datatable-large"}
,{ "sTitle": "Customer", "sClass": "datatable-medium" }
,{ "sTitle": "Manufacturer", "sClass": "datatable-large" }
,{ "sTitle": "Quantity", "sClass": "datatable-medium datatable-center" }
,{ "sTitle": "Price", "sClass": "datatable-medium datatable-center" }
,{ "sTitle": "Description", "sClass": "" }
,{ "sTitle": "Urgent", "sClass": "" }
,{ "sTitle": "Search", "sClass": "" }
,{ "sTitle": "", "sClass": "datatable-tiny datatable-center", "bSortable": false }
]
,"bJQueryUI": true
,"sPaginationType": "full_numbers"
,"bProcessing": true
,"bServerSide": true
,"sAjaxSource": "<?php echo $URL;?>"
,"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
}
,"bScrollCollapse": true
,"fnDrawCallback": function() {
$('.hidden-img').each(function(){
$(this).click();
});
}
,"aoColumnDefs": [
{"fnRender": function (o) {
return "<img src='<?= "img/img.png"; ?>' border='0' width='1px' height='1px' class='hidden-img'> ";
},"bSortable": false, "aTargets": [0]},
{"fnRender": function (o) {
return o.aData[10];
},"bSortable": false, "aTargets": [3]},
{"fnRender": function (o) {
return "$<input type='text' value='"+CurrencyFormatted(o.aData[7], true)+"' class='input-target_price'>";
},"aTargets": [7]},
{"bSortable": false, "aTargets": [1]},
{"bSortable": false, "aTargets": [2]},
{"bSortable": false, "aTargets": [5]},
{"fnRender": function (o) {
return "<input type='text' value='"+o.aData[6]+"' class='input-qty'>";
}, "bSortable": false, "aTargets": [6]},
{"bSortable": false, "aTargets": [7]},
{ "bSortable": false, "bSearchable": false, "bVisible": false, "aTargets": [ 4 ] },
{ "bSortable": false, "bSearchable": false, "bVisible": false, "aTargets": [ 8 ] },
{ "bSortable": false, "bSearchable": false, "bVisible": false, "aTargets": [ 9 ] },
{ "bSortable": false, "bSearchable": false, "bVisible": false, "aTargets": [ 10 ] },
{"fnRender": function (o) {
return "<img src='<?= "img/img.png"; ?>' border='0' class='save' rel='"+o.aData[11]+"' >";
},"aTargets": [11]}
] // end aoColumnDefs
});//end Datatable
希望這會有所幫助,我有很多的調整數據表在過去的麻煩,但他們是偉大的,當你得到它的竅門!
祝你好運。
我想我的問題是與做for循環,而不是設置。謝謝。 – user1959500
好的,然後看看使用jQuery的.on()方法。 (「#dataTable tbody tr」).on(「click」,function(){){ alert($(this).text()); }); 也許這些項目是動態添加到DOM的,所以你需要.on() - 祝你好運!參考:http://api.jquery.com/on/ – Drace