У меня проблема с моим последним столбцом ( индекс столбца 15 ), который переупорядочивается в моей таблице данных.Даже когда не объявлено отключенное упорядочение в этом столбце, я не могу упорядочить его программно, но даже вручную.Мои остальные столбцы упорядочены очень хорошо.
<table id="tblRequestLoaLedger" class="table table-bordered table-striped table-hover table-condensed w-100">
<thead class="table-info text-center justify-content-center">
<tr>
<th scope="col" class="pl-1 pr-1">Options</th>
<th scope="col" class="pl-1 pr-1">Issue LOA</th>
<th scope="col" class="pl-1 pr-1">Discussions</th>
<th scope="col">Request No.</th>
<th scope="col">Date Requested</th>
<th scope="col">Date Availed</th>
<th scope="col">Member ID</th>
<th scope="col">Member Name</th>
<th scope="col">Hospital | Clinic</th>
<th scope="col">Account Name</th>
<th scope="col">Status</th>
<th scope="col">LOA No.</th>
<th scope="col">Approved Amount</th>
<th scope="col">Reason</th>
<th scope="col">LOA Code</th>
<th scope="col">Has New Msgs</th>
</tr>
</thead>
<tbody>
<tr role="row" class="odd">
<td class="text-center">
<div class="dropdown">
<button class="btn btn btn-outline-info btn-secondary dropdown-toggle dropdown-toggle-ellipsis" type="button" id="dropdownRLoaOpt" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="javascript:void(0);" onclick="GetImages(4579);">View Images</a>
<a class="dropdown-item" href="javascript:void(0);" onclick="GetMemberProfile(64378);">View Member's Profile</a>
</div>
</div>
</td>
<td scope="row" class="text-center">
<a class="btn btn btn-outline-info btn-circle" href="javascript:void(0);" onclick="GetLOAAvailmentDetails(4579);">
<i class="fa fa-file" aria-hidden="true"></i>
</a>
</td>
<td class="text-center" data-order="0">
<a class="btn btn btn-outline-info btn-circle" href="javascript:void(0);" onclick="GetMsgsRequestLOA(4579, 64378, 'ADVENTO, NANETH', this);">
<i class="fa fa-comments"></i>
<span class="badge badge-danger ml-1"></span>
</a>
</td>
<td class="">04579</td>
<td class="text-center">09/06/2018</td>
<td class="text-center">09/06/2018</td>
<td class="text-right">86761-00</td>
<td class="text-nowrap">ADVENTO, NANETH</td>
<td class="text-nowrap">A. ZARATE GENERAL HOSPITAL</td>
<td class="text-nowrap">ACCONA GENERAL MERCHANDISE</td>
<td class="text-center align-middle"><span class="badge badge-secondary">CANCELLED</span></td>
<td></td>
<td class="text-right">0.00</td>
<td></td>
<td>4580</td>
<td class="sorting_1">0</td>
</tr>
</tbody>
</table>
Javascript
$(document).ready(function () {
InitTblRequestLoa();
TblRequestLoaActions();
$('#aNewMsgs').on('click', function () {
$('#fDateReq').val('');
$('#fDateReqTo').val('');
InitTblRequestLoa().order([15, 'desc']).draw();
});
});
function InitTblRequestLoa() {
return $('#tblRequestLoaLedger').DataTable({
retrieve: true,
dom: "<'row'<'col-12't>>" +
"<'row'<'col-6'i><'col-6'l>>" +
"<'row'<'col-12'p>>",
order: [[3, 'desc']],
language: {
emptyTable: 'No data available'
},
columnDefs: [
{
targets: [0, 1, 2],
orderable: false
},
{
targets: [14],
visible: false
},
{
targets: [15],
type: 'num'
}
]
,
stateSave: true,
stateSaveCallback: function (settings, data) {
var api = new $.fn.dataTable.Api(settings);
localStorage.setItem(api.table().node().id, JSON.stringify(data));
},
stateLoadCallback: function (settings, callback) {
var api = new $.fn.dataTable.Api(settings);
try {
return JSON.parse(localStorage.getItem(api.table().node().id));
} catch (e) { }
}
});
}
Как видите, я попытался указать тип столбца как num
,и до сих пор не повезло.Есть какие-нибудь решения для этого?
решено
В DataTables возникла проблема с упорядочением столбца Has Msgs
, потому что я пытался присвоить данные ячейке, используя эту строку:
$(thisRow).find('td:nth-child(15)').html("1");
Оказывается, DataTables не распознает это назначение, и мне пришлось «действительно» назначать данные через API DataTables, cell.data () , благодаря @samabcde.
tblRequestLoaLedger.cell(rowIndex, 15).data('1');