The code below is designed to search in a table. I'm using datatable jQuery and I'm trying to minimize the number of imported records by searching before using the built in filtering feature.
My problem starts with the second search onwards. you can see from the attached image that select function fires proportionally with the number function calls.
Any idea why?
function srctbl() {
$("#RegSrc").dataTable().fnDestroy();
var RegSrctbl = $('#RegSrc').DataTable({
select: true,
scrollY: 200,
deferRender: true,
scroller: true,
rowId: 'Filenum',
//"processing": false,
//"serverSide": false,
"ajax": {
contentType: "application/json; charset=utf-8",
url: "../CONFIG/WebSerTblsSearch.asmx/SrcTblReg",
type: "Post",
data: function (dtParms) {
return JSON.stringify({
SrchTxt: $('#srctxt').val(),
FnameSrctxt: $('#fnamesrc').val(),
SnameSrctxt: $('#snamesrc').val(),
TnameSrctxt: $('#tnamesrc').val(),
LnameSrctxt: $('#lnamesrc').val(),
TelSrcTxt: $('#telsrc').val(),
SSNSrcTxt: $('#ssnsrc').val(),
EmailSrctxt: $('#emailsrc').val(),
DOBSrcTxt: $('#dobsrc').val()
});
},
dataFilter: function (res) {
var parsed = JSON.parse(res);
var morp = JSON.parse(parsed.d);
return JSON.stringify({ data: morp });
},
error: function (x, y) {
console.log(x);
}
},
deferRender: true,
columns: [
{ data: "Filenum" },
{ data: "FullName" },
{ data: "DOB" }
],
select: {
style: 'single',
blurable: true
},
});
$("#RegSrc").on("click", "tr", function () {
console.log($(this).children(":first").text());
$("#trgtval").val(($(this).children(":first").text()))
});
}
console.log() showing number of event fires with each selection after the first function call
