tonytomov/jqGrid — Issue #214: Add bindChange and getValue to jqFilter
Author: emielJ
Created: 2011-12-09 15:22:06+00:00
State: open

When creating filters with complex UI elements (for instance date-time input which consists of two separate input fields, of when the text that was entered has to be processed before it can be used in a filter (for instance convert the input of a date field into a JavaScript `Date` object) it would be nice to have alternative ways to get the value from the input or to attach the on change event on a different way than the default way.

In order to accomplish this, I have created the following functions:

function getValue($element, p) {
if ($.isFunction(p.getValue)) {
return p.getValue($element, p);
}
return $element.val();
}

function bindChange($element, p, change) {
if ($.isFunction(p.bindChange)) {
return p.bindChange($element, p, change);
}
return $element.bind('change', change);
}

These functions can be used to replace the calls to

rule.data = $(this).val();

into

rule.data = getValue($(this), that.p);

and the binding of the change events like

$(".input-elm",trpar).bind('change',function() { ...

into

bindChange($(".input-elm", trpar), that.p, function () { ...

Of course the values `getValue` and `bindChange` must be copied from the searchGrid options during the call in which `jqFilter` is created.