We are using KnockoutJS for handling UI and moving parts in UI.
So here is the problem:
We have grid on which we have filter columns. It filters data on tab-out. Recently we received a request to Filter data on Enter. Since knockout provide subscribe method that automatically triggers action i want. Is there a way to have custom implementation of subscribe method which can be triggered on enter.
var triggerQueryIfOk = function () {
if (!self.isLoading() && !self.isOpening) self.runQuery();
};
self.filters.empName.subscribe(triggerQueryIfOk);
};
self.getQueryParameters = function () {
return {
empName: self.filters.empName() };
};
self.runQuery = function () {
if (!self.isLoading()) {
self.isLoading(true);
// prepare query data
var query = self.getQueryParameters();
// hit server
$.ajax({
url: self.getEmployeesUrl,
type: "POST",
data: JSON.stringify(query),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (rawInvestmentsData) {
processEmployees(rawInvestmentsData);
self.isLoading(false);
},
error: function () {
self.isLoading(false);
}
});
}
};
Judah’s answer is close except the onkeydown method should look like this(at least for me it did):