Search Function not working for few columns. [URGENT HELP]
Search Function not working for few columns. [URGENT HELP]
Hello,
This is my first post and i am very new to dataTables. Please excuse me for asking any wrong question.
So i am making a dropdown to select the item that i have to search. I have two dropdowns. First one is for selecting the practices which is working fine for me. Other one is for selecting status which is causing me trouble. I am unable to search any entry in the Status column of my dataTable. Either from the code mentioned below or from the search box provided on top of the dataTable.
Here is my code
$(document).ready(function () {
var table = $('#members').dataTable({
processing: true,
serverSide: true,
lengthMenu: [[20, 50, 100], [20, 50, 100]],
initComplete: function () {
this.api().column(3).every(function () {
var column = this;
var select = $('<select><option value="">--Select Practice--</option></select><br/><br/>')
.appendTo($('#filter'))
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? val : '', true, false)
.draw();
});
if (brand == 'All') { //In All companies Case
var sorted_arr = practices.sort(function (a, b) {
return (a._id.practice > b._id.practice) ? 1 : ((b._id.practice > a._id.practice) ? -1 : 0);
}); //Sort the Array
for (var i = 0; i < practices.length; i++) {
var rec = practices[i]._id;
if (rec) {
select.append('<option value="' + rec.practiceabbr + '">' + rec.practice + '</option>')
}
}
}
else { //In case of Individual Companies i.e Smile Magic, Family Smile, Sol River
var sorted_arr = practices.sort(function (a, b) {
return (a._id.practiceabbr > b._id.practiceabbr) ? 1 : ((b._id.practiceabbr > a._id.practiceabbr) ? -1 : 0);
}); //Sort the Array
for (var i = 0; i < practices.length; i++) {
var rec = practices[i]._id;
if (rec) {
if (rec.brand == brand) {
select.append('<option value="' + rec.practiceabbr + '">' + rec.practice + '</option>')
}
}
}
}
});
// This section is causing me trouble. This certainly creates a drop down list but when i select any item i get No records found in the table.
var column = this.api().columns(14);
var selectStatus = $('<select><option value="">--Select Status--</option><option value="Dropped Patient">Dropped Patient</option><option value="Recare - Future Appointment">Recare - Future Appointment</option><option value="Recare - No Future Appointment">Recare - No Future Appointment</option><option value="New Patient">New Patient</option></select><br/><br/>')
.appendTo($('#filterStatus'))
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? val : '', true, false)
.draw();
});
},
ajax: {url: '/members/datatable?company=' + window.brand, "type": "POST"},
fnCreatedRow: function (nRow, aData, iDataIndex) {
if(aData.Status){
$('td:eq(14)', nRow).html("<div id='status_" + aData['Subscriber ID'] + "' data-subscriber='" + aData['Subscriber ID'] + "'>" + aData.Status + "</div>");
}else{
$('td:eq(14)', nRow).html("<div id='status_" + aData['Subscriber ID'] + "' data-subscriber='" + aData['Subscriber ID'] + "'> No Status Found</div>");
}
},
dom: 'Bfrtip',
buttons: [
'print'
],
columns: [
{data: "Subscriber ID"},
{data: "First Name"},
{data: "Last Name"},
{data: "Practice"},
{data: "Address1"},
{data: "City"},
{data: "State"},
{data: "Phone"},
{data: "Date of Birth", "defaultContent": "<i>Not set</i>"},
{data: "Age"},
{data: "Extract Date"},
{data: "Days Extracted"},
{data: "notes", "defaultContent": "<i>Add Note</i>"},
{data: "notestimestamp", "defaultContent": "<i> No Notes Added </i>"},
{data: "Status", "defaultContent":"<i>No Status Found</i>"}
]
});
});
And this is my server side code
{
method: 'POST',
path: '/members/datatable',
config: {
auth: 'simple',
handler: function (request, reply) {
Data.dataTable(options).then(function (members) {
Data._collection = 'OpenDental';
Data.findData({}).then(function (opendata) {
opendata.forEach(function (odata) {
for (var j = 0; j < members.data.length; j++) {
temp = members.data[j];
if (!temp['Status'] || temp['Status'] == 'New Patient') {
if (temp['Subscriber ID'] == odata['SubscriberID']) {
if (odata['NextApt']) {
temp['Status'] = 'Recare - Future Appointment';
members.data[j] = temp;
break;
}
else {
temp['Status'] = 'Recare - No Future Appointment';
members.data[j] = temp;
break;
}
}
else {
temp['Status'] = 'New Patient';
members.data[j] = temp;
}
}
temp = {};
}
});
reply(members);
});
});
});
});
}
}
}