我要在搜索表行列时选择表的第一行,但是我也将选择的第一行选择的代码放到了那,但是我该怎么解决?
var table = this.oTable = $('#mytable').DataTable({
"lengthMenu": [
[20, 40, 60, 80, 100],
[20, 40, 60, 80, 100]
],
scrollX: true,
scrollY: $(window).height() - 232,
"stateSave": true,
"info": true,
// "aaSorting": [[ 1, "desc" ]],
"ordering": true,
"order": [
[1, "desc"]
],
language: {
oPaginate: {
sNext: '<i class="fa fa-angle-right"></i>',
sPrevious: '<i class="fa fa-angle-left "></i>',
sFirst: '<i class="fa fa-angle-double-left"></i>',
sLast: '<i class="fa fa-angle-double-right"></i>'
},
"sProcessing": '<div class="fulloverlay"> <img id="loading-image" src="' + base_url + '/assets/v1/images/loader.gif"> </div>',
},
columnDefs: [{
targets: [0],
"orderable": false,
},
{
"orderable": false,
targets: [0, 2]
}
],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": base_url + 'index.php/Customer_Category/tableList1',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ": 20,
"pageLength": 40,
searching: false,
orderCellsTop: true,
fixedHeader: true,
"bLengthChange": false,
"fnInitComplete": function() {},
'fnServerData': function(sSource, aoData, fnCallback) {
var cnt = 0;
$('#mytable thead tr:eq(1) th').each(function(i) {
if ($("#searchFilter_" + cnt).attr('type') == 'checkbox') {
if ($("#searchFilter_" + cnt).prop("checked") == true) {
var val = 1;
} else if ($("#searchFilter_" + cnt).prop("checked") == false) {
var val = 0;
}
aoData.push({
"name": "searchFilter_" + cnt,
"value": val
});
} else {
aoData.push({
"name": "searchFilter_" + cnt,
"value": $("#searchFilter_" + cnt).val()
});
}
cnt++;
});
$.ajax({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': fnCallback
});
},
rowCallback: function(row, data, index) {
if (index % 2 == 0) {
$(row).removeClass('myodd myeven');
$(row).addClass('myodd');
} else {
$(row).removeClass('myodd myeven');
$(row).addClass('myeven');
}
},
});
答案 0 :(得分:0)
您可以使用initComplete
选择第一条记录。
$('#mytable').DataTable( {
"initComplete": function () {
var table = $('#myTable').DataTable();
table.row(':eq(0)', { page: 'current' }).select();
}
});