我在函数的页面onload
事件中创建了一个数据表。在onchange
控件的select
事件中,我需要获取该控件值并将其传递给具有数据表的函数。
在我自己的方法中,我还需要从中获取数据并将其设置为数据表。为此,我使用的是destroy()
函数,它会抛出类似
无法在
insertBefore
上执行Node
:插入新节点的节点不是此节点的子节点。
在互联网上搜索后,我使用了retrieve:true
属性,但是当前的数据没有刷新。
有人可以就此提出一些建议吗?以下是我的示例代码。
function getmailsdata() {
$.cordys.ajax({
method: "Getclassifiedmails",
namespace: "http://schemas.cordys.com/IMSPackage",
parameters: {
emailbox:$("#inp_mailbox").val(),
emailid:'',
classification:$("#classifiedtype").val(),
incidentno:'',
subject:'',
fromdate:'',
todate:'',
body_content:''
},
dataType: '* json',
success: function (result) {
/*
if (Getmaildetailstable != null) {
Getmaildetailstable.destroy();
}
*/
if ( $.fn.DataTable.isDataTable('#Getmaildetailstable') ) {
$('#Getmaildetailstable').DataTable().destroy();
//$('#Getmaildetailstable').html("");
}
Getmaildetailstable = $('#Getmaildetailstable').DataTable({
"data": ((result.tuple == undefined) ? [] : ((result.tuple.length == undefined) ? [result.tuple] : result.tuple)),
"columns": [{
className: 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="checkbox">';
},
defaultContent: "",
"targets": 0,
}, {
"targets": 1,
"data": "old.EMAIL.STARRED_FLAG",
visible: false,
}, {
"targets": 2,
"data": "old.EMAIL.IMPORTANT_FLAG",
visible: false,
}, {
"targets": 3,
"data": "old.EMAIL.EMAIL_ID",
visible: false,
}, {
"targets": 4,
"data": "old.EMAIL.EMAILBOX",
visible: false,
}, {
"targets": 5,
"data": "old.EMAIL.LOGICAL_ID",
visible: false,
}, {
"targets": 6,
defaultContent: "",
"data": "image",render: getStarredflag,
visible: true,
}, {
"targets": 7,
defaultContent: "",
"data": "image",render: getImportantflag,
visible: true,
}, {
"targets": 8,
"data": "old.EMAIL.SUBJECT",
"render": function ( data, type, row ) {
return '<a href="javascript:void(0)" onclick="openmaildetailsfunction()">' + data + '</a>';
},
visible: true,
}, {
"targets": 9,
"data": "old.EMAIL.attachments",
visible: false,
}, {
"targets": 10,
"data": "old.EMAIL.MAIL_SIZE",
visible: false,
}, {
"targets": 11,
"data": "old.EMAIL.CREATE_DATE",
visible: true,
}, {
"targets": 12,
"data": "old.EMAIL.RECEIVE_DATE",
visible: false,
}, {
"targets": 13,
"data": "old.EMAIL.FROM_ADDRESS",
visible: true,
}, {
"targets": 14,
"data": "old.EMAIL.TO_ADDRESS",
visible: true,
}, {
"targets": 15,
"data": "old.EMAIL.INCIDENT_NO",
visible: false,
}, {
"targets": 16,
"data": "old.EMAIL.CLASSIFICATION_TYPE",
visible: false,
}, {
"targets": 17,
"data": "image",render: getImg,
visible: true,
}],
select: {
style: 'multi',
selector: 'td:first-child'
}
});
},
async:false,
error: function(err) {
console.log(err);
},
order: [
[4, 'asc']
],
});
}
window.onload = function () {
var select = document.getElementById("classifiedtype");
for(var i = 2011; i >= 1900; --i) {
var option = document.createElement('option');
option.text = option.value = i;
select.add(option, 0);
}
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div class="panel-body">
<table id="Getmaildetailstable" class="table table-striped display" width="100%">
<thead>
<tr>
<th><input name="select_all" value="1" type="checkbox"></th>
<th>Starredflag</th>
<th>Importantflag</th>
<th>Mailid</th>
<th>Mailbox</th>
<th>LogicalID</th>
<th>Starred</th>
<th>Important</th>
<th>Subject</th>
<th>attachments</th>
<th>mailsize</th>
<th>Created On</th>
<th>Received On</th>
<th>From</th>
<th>To</th>
<th>Incident_no</th>
<th>classification</th>
<th>Attachments</th>
</tr>
</thead>
</table>
</div>
<div>
<div class="form-group col-md-2">
<label for="classifiedtype" class="control-label">Classified Type</label>
<select id="classifiedtype" class="form-control" onchange="getmailsdata()">
</select>
</div>
</div>