나는이 아주 기본적인 테이블을 표시하는 회사가 있습니다 따라 의견을 읽어Ajax 응답은 datatables 열을 렌더링
oTable = $('#companies').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "ajax/companies/get_companies.ajax.php"
"type": "POST"
},
"columns": [
{ "bSearchable": true, "data": "company_name" },
{ "bSearchable": true, "data": "company_field" },
{ "bSearchable": true, "data": "company_area" },
//{ "bSearchable": true, "data": "relative_items" }, //displays id numbers from DB eg: (6, 32, 17, 24) but I dont want to display just ID numbers
{ // Here I convert the item ID's array to Item Names
"bSearchable": true,
"data": "relative_items",
"mRender": function (data) {
var trimResponse = "initialValue"; //if I don't set this variable I get datatables error...
$.ajax({
type: "POST",
url: "companies/get_relative_items.php",
data: "datastring="+data,
success: function(resp){
trimResponse = $.trim(resp);
console.log(trimResponse); //works! I can see the item names in console log
}
})
return trimResponse; //HOWEVER, datatables display the initial value of this variable and NOT the new one set by the above function
}
},
{ "bSearchable": false, "data": "subscription_end" }
],
"order": [[1, 'asc']]
});
//alert(trimResponse); //if commented out, it also displays the initial value and not the one acquired by ajax
:
<table id="companies" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Company Name</th>
<th class="hidden-xs hidden-sm hidden-md">Business Field</th>
<th class="hidden-xs hidden-sm">Area</th>
<th class="hidden-xs hidden-sm">Related Items</th>
<th class="hidden-xs">Subscription ends</th>
</tr>
</thead>
</table>
나는 "datatables 1.10"를 사용하고 다음과 같은 초기화 스크립트를 javascript를 사용하면 이미 네 번째 열에서 각 회사의 관련 항목 (다른 DB 테이블에 저장되어 있음)을 표시하려고한다는 것을 알았을 수 있습니다.
지금까지 ID 번호를 표시 할 수 있지만 ID 번호가 "인간 친화적"이 아니기 때문에 ajax를 사용하여 ID 번호 배열 (예 : 2, 5, 3, 12)을 실제 이름으로 반환합니다 각 품목 ID (예 : 셔츠, 바지, 양말, 자켓). 내가 볼 수 있지만
그러나이 이름의 배열은 datatables 네 번째 열 표시를 변수 "trimResponse"및 NOT 아약스에 의해 주어진 새 값의 초기 값을 ... 콘솔에 올바르게 표시datatables 열에 아약스 응답을 표시하는 방법에 대한 제안 사항이 있으십니까? 미리 감사드립니다.