Custom fnFilter with few textboxes
Custom fnFilter with few textboxes
I made custom filtering with some textboxes, and when I focusIn in another textbox datatable forget last search
I have few data in one column, for example FirstName, LastName, RegistryCode...
"columns": [
{
"data": null,
"className": "left",
"render": function (data, type, res, meta) {
return personData(res.PersonFirstName, res.PersonLastName, res.PersonDomesticPersonRegistryCode);
}
}
]
Then I have function
function personData(firstName, lastName, jmbg) {
var html = [
'<span style="display:none">spanFirstName</span>' + firstName + ' ' + '<span style="display:none">spanLastName</span>' + lastName,
'<span style="display:none">spanJmbg</span>' + jmbg
].join("\n");
return html;
};
On Document ready I call
$(document).ready(function () {
var dataTable = $('#patientsTable').dataTable();
findByRegularExpression(dataTable, '#txtRegistryCode', 'spanJmbg');
findByRegularExpression(dataTable, '#txtFirstName', 'spanFirstName');
findByRegularExpression(dataTable, '#txtLastName', 'spanLastName');
})
I Finally I have this method for search:
function findByRegularExpression(table, txtElement, spanText) {
$(txtElement).on('keyup', function () {
var value = spanText + this.value;
table.fnFilter(value, null, true, false).draw();
});
}
And when I insert some text in textbox with id='txtFirstName', for example Allan it search just data with Allan first name, and doesn't look other data. If I enter text in textbox with id='txtLastName' , for example Ramos, now it search just Ramos in PersonLastName, but it forget entered Allan for first name.
My question is, how to get current data in table, and than continue search...
I think the problem is because in document ready I call
var dataTable = $('#patientsTable').dataTable();
Any Suggestion?